标签:c++ project euler
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
标签:c++ project euler
原文地址:http://blog.csdn.net/youb11/article/details/46358191