projectEuler pro9

Problem 9

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.

 
JAVA:
 

public class P009 {
public static void main(String[] args){
int a=0,b=0,c=0;
int n = 0;
for(int i = 1;i<334;i++){
for(int j=i+1;j<1000;j++){
n = 1000-i-j;
if(i*i+j*j==n*n){
a = i;
b = j;
c = n;
break;
}
}
}
System.out.println(a*b*c);
}
}

posted on 2013-10-09 21:39  Monster_Ch  阅读(210)  评论(0编辑  收藏  举报

导航