Problem 9
Special Pythagorean triplet
A Pythagorean triplet is a set of three natural numbers, a < 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組成的集合,並滿足
例如,32 + 42 = 9 + 16 = 25 = 52。
有且只有一個畢達哥拉斯三元組滿足 a + b + c = 1000。求這個三元組的乘積abc。
暴力解....
#include<iostream>
void main()
{
int a,b,c;
for (a = 1; a < 334; a++)
for (c = 334; c < 1000; c++)
{
b = 1000 - a - c;
if (a*a + b*b == c*c)
{
std::cout << "這個數組爲:" << std::endl;
std::cout << "a= " << a << std::endl;
std::cout << "b= " << b << std::endl;
std::cout << "c= " << 1000 - a - b << std::endl;
std::cout << "abc=" << a*b*(1000 - a - b) << std::endl;
break;
}
}
system("pause");
}
最後的答案:31875000