Project Euler 39
Project Euler 39
题目
Integer right triangles
If \(p\) is the perimeter of \(a\) right angle triangle with integral length sides, \(\{a,b,c\}\), there are exactly three solutions for \(p = 120\). \[\{20,48,52\}, \{24,45,51\}, \{30,40,50\}\]
For which value of \(p \le 1000\), is the number of solutions maximised?
解决方案
使用第9题时得出的结论,枚举\(a\),即得到\(b\)的值:
\[b=\dfrac{p^2-2ap}{2(p-a)}\]
因此,直接对解进行判断。
代码
1 | N = 1000 |