Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* A Pythagorean triplet is a set of three natural numbers, a < b < c,
- * for which, a^2 + b^2 = c^2. For example,
- * 3^2 + 4^2 = 9 + 16 = 25 = 5^2. There exists exactly one Pythagorean
- * triplet for which a + b + c = 1000. Find the product abc. */
- #include <stdio.h>
- int main()
- {
- int x, y, z;
- for(z = 997; z > 2; z--)
- for(y = (999 - z) / 2 + 1; y > 1; y--)
- {
- x = 1000 - (y + z);
- if(x * x + y * y == z * z)
- {
- printf("%d\n", y * z * x);
- return(0);
- }
- }
- }
- /* 31875000
- *
- * real 0m0,003s
- * user 0m0,003s
- * sys 0m0,000s */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement