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?
#define N 1000
int main()
{
clock_t ts,te;
ts=clock();
int answer = 0;
int i,j,k;
int p,count,max = 0;
for (p = 5; p < N; p++)
{
count = 0;
for (i = 1; i < p-2; i++)
{
for (j = i; j < p-1 ;j++)
{
k = p - i - j;
if(k*k == j*j + i*i)
{
count++;
}
}
}
if (max < count)
{
max = count;
answer = p;
}
}
printf("\nanswer %d",answer);
te=clock();
printf("\ntime difference: %ds\n",(te-ts)/CLOCKS_PER_SEC);
getchar();
return 0;
}