ProjectEuler_P9
Question:
A Pythagorean triplet is a set of three natural numbers, a b
c, for which,
a2 + b2 = c2
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
C Code:
#include <stdio.h>
void main()
{
int i,j;
for(i = 1; i < 333;i++)
{
int flag = 0;
int uplegal = (1000 - i)/2;
for(j = i+1; j < uplegal ;j++)
{
int k = 1000 - i - j;
if(i*i + j*j == k*k)
{
printf("%d %d %d %d\n",i,j,k,i*j*k);
flag = 1;
break;
}
}
if(1 == flag)
break;
}
}
Answer:
31875000