Project Euler: Problem 9 Special Pythagorean triplet
2015-05-30 17:20
405 查看
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.
首先联立式子,消除c,得到关于ab的等式500000=1000a+1000b-ab
然后用a表示出b b=(500000-1000a)/(1000-a)
然后a从1开始取值,直到b为整数为止。
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.
首先联立式子,消除c,得到关于ab的等式500000=1000a+1000b-ab
然后用a表示出b b=(500000-1000a)/(1000-a)
然后a从1开始取值,直到b为整数为止。
#include <iostream> #include <string> using namespace std; int main() { int b; int i = 1; for (i = 1; i <= 998; i++) { if ((500000 - 1000 * i) % (1000 - i) == 0) { b = (500000 - 1000 * i) / (1000 - i); break; } } cout << i * b *( 1000 - i - b) << endl; system("pause"); return 0; }
相关文章推荐
- Django笔记(5) -- 站点管理
- Dive into Category
- hdu1754
- DragonBoard810使用记录
- Google Chrome快捷键大全
- Gossip算法
- Google 日历短信通知没有了
- Recommend for Reviewing design doc-from How Google Test Software
- (EM算法)The EM Algorithm
- 解决sdk更新问题 dl-ssl.google.com
- Google Chrome的使用感受
- Django笔记(4)-- Django的MTV模式
- 欧拉工程第45题:Triangular, pentagonal, and hexagonal
- 欧拉工程第44题:Pentagon numbers
- Django笔记---模板的使用
- 分类 category使用
- Django学习(五) 定义视图以及页面模板
- Django搭建及源码分析(二)
- maven项目使用cargo自动部署:
- GPS坐标互转:WGS-84(GPS)、GCJ-02(Google地图)、BD-09(百度地图)