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 ≤ 1000, is the number of solutions maximised?
#include <iostream> using namespace std; int main() { int ans = 0; int maxp = 0; for (int i = 12; i <= 1000; i++) { int maxc = 0; for (int a = 1; a < i; a++) { for (int b = 1; b < a; b++) { int c = i - a - b; if (c < 0) break; if (a*a + b*b == c*c) maxc++; } } if (maxc>ans) { ans = maxc; maxp = i; } } cout << ans << " " << maxp << endl; system("pause"); return 0; }
版权声明:本文博主原创文章,博客,未经同意不得转载。
Project Euler:Problem 39 Integer right triangles
原文:http://www.cnblogs.com/gcczhongduan/p/4856731.html