Find adjacent primes which differ by a square integer: Difference between revisions

Content added Content deleted
(Realize in F#)
(Added XPL0 example.)
Line 627: Line 627:
981,887 - 981,823 = 64 = 8 x 8
981,887 - 981,823 = 64 = 8 x 8
997,877 - 997,813 = 64 = 8 x 8
997,877 - 997,813 = 64 = 8 x 8
</pre>

=={{header|XPL0}}==
<lang XPL0>func IsPrime(N); \Return 'true' if odd N > 2 is prime
int N, I;
[for I:= 3 to sqrt(N) do
[if rem(N/I) = 0 then return false;
I:= I+1;
];
return true;
];

int N, P0, P1, D, RD;
[P0:= 2;
for N:= 3 to 1_000_000-1 do
[if IsPrime(N) then
[P1:= N;
D:= P1 - P0; \D is even because odd - odd = even
if D >= 64 then \the next even square > 36 is 64
[RD:= sqrt(D);
if RD*RD = D then
[IntOut(0, P1); Text(0, " - ");
IntOut(0, P0); Text(0, " = ");
IntOut(0, D); CrLf(0);
];
];
P0:= P1;
];
N:= N+1; \step by 1+1 = 2 (for odd numbers)
];
]</lang>

{{out}}
<pre>
89753 - 89689 = 64
107441 - 107377 = 64
288647 - 288583 = 64
368021 - 367957 = 64
381167 - 381103 = 64
396833 - 396733 = 100
400823 - 400759 = 64
445427 - 445363 = 64
623171 - 623107 = 64
625763 - 625699 = 64
637067 - 637003 = 64
710777 - 710713 = 64
725273 - 725209 = 64
779477 - 779413 = 64
801947 - 801883 = 64
803813 - 803749 = 64
821741 - 821677 = 64
832583 - 832519 = 64
838349 - 838249 = 100
844841 - 844777 = 64
883871 - 883807 = 64
912167 - 912103 = 64
919511 - 919447 = 64
954827 - 954763 = 64
981887 - 981823 = 64
997877 - 997813 = 64
</pre>
</pre>