guangzhou



shanghai

Recent posts:
Blog index
About
RSS

Project Euler 9–Special Pythagorean triplet

October 09, 2017     欧拉计划   992   

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.

一个毕达哥拉斯三元组是一个包含三个自然数的集合,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
Completed on Wed, 24 Jul 2013, 08:53

如果文章对您有帮助,欢迎点击下方按钮打赏作者

Comments

No comments yet.
To verify that you are human, please fill in "七"(required)