首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

(Problem 九)Special Pythagorean triplet

2013-11-30 
(Problem 9)Special Pythagorean triplet?b??c, for which,a2?+?b2??c2For example, 32?+ 42? 9 + 16

(Problem 9)Special Pythagorean triplet
?b?(Problem 九)Special Pythagorean triplet?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.

?

原题大意:

一个毕达哥拉斯三元组是一个包含三个自然数的集合,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

热点排行