(Problem 9)Special Pythagorean triplet
?b??c, for which,
For example, 32?+ 42?= 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which?a?+?b?+?c?= 1000.
Find the product?abc.
?
原题大意:
一个毕达哥拉斯三元组是一个包含三个自然数的集合,a<b<c,满足条件:
a2?+?b2?=?c2例如:32?+ 42?= 9 + 16 = 25 = 52.
已知存在并且只存在一个毕达哥拉斯三元组满足条件a?+?b?+?c?= 1000。
找出该三元组中abc的乘积。
#include<stdio.h>#include<math.h>#include<string.h>#include<ctype.h>#include<stdlib.h>#include<stdbool.h>void show(){ int a,b,c; for(a=1; a<333; a++) { for(c=333; c<500; c++) { b=1000-a-c; if(a*a+b*b==c*c) { printf("%d\n",a*b*c); return; } } }}int main(){ show(); return 0;}
?
Answer:31875000