Pythagorean quadruples: Difference between revisions
Content added Content deleted
(→{{header|PicoLisp}}: Add Python) |
(Added Java) |
||
Line 296: | Line 296: | ||
<pre> |
<pre> |
||
1 2 4 5 8 10 16 20 32 40 64 80 128 160 256 320 512 640 1024 1280 2048 |
1 2 4 5 8 10 16 20 32 40 64 80 128 160 256 320 512 640 1024 1280 2048 |
||
</pre> |
|||
=={{header|Java}}== |
|||
{{trans|Kotlin}} |
|||
<lang java>public class PythagoreanQuadruple { |
|||
static final int MAX = 2200; |
|||
static final int MAX2 = MAX * MAX * 2; |
|||
public static void main(String[] args) { |
|||
boolean[] found = new boolean[MAX + 1]; // all false by default |
|||
boolean[] a2b2 = new boolean[MAX2 + 1]; // ditto |
|||
int s = 3; |
|||
for (int a = 1; a <= MAX; a++) { |
|||
int a2 = a * a; |
|||
for (int b = a; b <= MAX; b++) a2b2[a2 + b * b] = true; |
|||
} |
|||
for (int c = 1; c <= MAX; c++) { |
|||
int s1 = s; |
|||
s += 2; |
|||
int s2 = s; |
|||
for (int d = c + 1; d <= MAX; d++) { |
|||
if (a2b2[s1]) found[d] = true; |
|||
s1 += s2; |
|||
s2 += 2; |
|||
} |
|||
} |
|||
System.out.printf("The values of d <= %d which can't be represented:\n", MAX); |
|||
for (int d = 1; d <= MAX; d++) { |
|||
if (!found[d]) System.out.printf("%d ", d); |
|||
} |
|||
System.out.println(); |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
The values of d <= 2200 which can't be represented: |
|||
1 2 4 5 8 10 16 20 32 40 64 80 128 160 256 320 512 640 1024 1280 2048 |
|||
</pre> |
</pre> |
||