Skip to content

Instantly share code, notes, and snippets.

@clementi
Created March 2, 2011 23:19
Show Gist options
  • Save clementi/851989 to your computer and use it in GitHub Desktop.
Save clementi/851989 to your computer and use it in GitHub Desktop.
Project Euler Problem 39 Solution
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