[Project Euler]加入欧拉 Problem 9
生活随笔
收集整理的這篇文章主要介紹了
[Project Euler]加入欧拉 Problem 9
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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
a+b+c = 1000
a <? b < c
a*a + b*b = c*c
歐拉項(xiàng)目第九題#include <stdio.h> #include <stdlib.h>int main(int argc, char *argv[]) {int a, b, c;double product;for(a = 1; a < 500; a++) //這里可以大致給a,b,c 確定下范圍,減少循環(huán)次數(shù) for(b = 1; b < 500; b++)for(c = 300; c < 1000; c++) {if((a + b + c ==1000) && (a * a + b * b == c * c)){if(a < b){double product = a*b*c;printf("%lf", product);}}}system("PAUSE"); return 0; }轉(zhuǎn)載于:https://www.cnblogs.com/herbert/archive/2011/01/27/1946325.html
總結(jié)
以上是生活随笔為你收集整理的[Project Euler]加入欧拉 Problem 9的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IDEA 导出UML类图
- 下一篇: android获取网络图片