-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem039.java
More file actions
31 lines (27 loc) · 757 Bytes
/
problem039.java
File metadata and controls
31 lines (27 loc) · 757 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
31
package project_beuler;
public class problem039 {
// If p is the perimeter of a right angle triangle with integral length sides,
// {a,b,c}, there are exactly three solutions for p = 120.
//
// {20,48,52}, {24,45,51}, {30,40,50}
//
// For which value of p ≤ 1000, is the number of solutions maximized?
public static void main(String[] args) {
// TODO Auto-generated method stub
int max = -1;
int length = 0;
for(int p = 1+1+1; p <= 1000; p++) {
int current = 0;
for(int a = 1; a <= (double) 2/3*p; a++) {
for(int b = 1; b <= a; b++)
if(Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)) == (p-b-a))
current++;
}
if(current > length) {
max = p;
length = current;
}
}
System.out.println(max+" "+length);
}
}