- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
Latest commit
30 lines (25 loc) · 604 Bytes
/
Copy pathMain.java
File metadata and controls
30 lines (25 loc) · 604 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
@author: mc-es
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.
Answer: 31875000
*/
publicclassMain {
publicstaticvoidmain(String[] args) {
for (inta = 1; a < 1000; a++) {
for (intb = a + 1; b < 1000; b++) {
intc = 1000 - a - b;
if (c > b) {
if (a * a + b * b == c * c) {
System.out.println(a * b * c);
return;
}
}
}
}
}
}