Created
March 2, 2011 23:19
-
-
Save clementi/851989 to your computer and use it in GitHub Desktop.
Project Euler Problem 39 Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
int max = 0; | |
int bestP = 0; | |
for (int p = 1; p <= 1000; p++) { | |
int found = 0; | |
for (int a = 1; a <= p / 4; a++) { | |
for (int b = 1; b <= (p - a) / 2; b++) { | |
double c = Math.sqrt(a * a + b * b); | |
if (a + b + c == p) | |
found++; | |
} | |
} | |
if (found > max) { | |
max = found; | |
bestP = p; | |
} | |
} | |
System.out.println(bestP); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment