Project Euler 195
题目
Inscribed
circles of triangles with one angle of degrees
Let’s call an integer sided triangle with exactly one angle of degrees a 60-degree triangle.
Let be the radius of the
inscribed circle of such a -degree triangle.
There are -degree triangles for which .
Let be the number of -degree triangles for which , so and .
Find .
解决方案
令 。根据余弦定理,假设三角形两边为长度 ,第三条边的长度 ,其对角为 ,那么 满足:
这篇文章提到了一种构造出一组本原三元组 (即 )满足 的方法:如果 , 那么有:
或者是
根据等积法,不难发现内切圆的半径 满足 。
分别代入式 ,分别得到
因此,根据 式枚举出所有 的本原三元组后,计算对应非本原三元组的数量即可。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #include <bits/stdc++.h> using namespace std; const int N = 1053779; double eps=1e-8; double sq3=sqrt(3); int main() { int ans = 0; for (int m = 1; 0.5 * sq3 * m <= N; m++) { double r; for (int n = 1; n < m && (r = 0.5 * sq3 * m * n - eps) <= N; n++) { if ((m - n) % 3 && __gcd(m, n) == 1) { ans += int(1.0 * N / r + eps); } } } double c = 0.5 / sq3; for (int n = 1; c * (2 * n + 1) <= N; n++) { double r; for (int m = n + 1; (r = c * (m - n) * (2 * n + m) - eps) <= N; m++) { if ((m - n) % 3 && __gcd(m, n) == 1) { ans += int(1.0 * N / r + eps); } } } printf("%d\n", ans); }
|