Quadrat special primes: Difference between revisions

Content added Content deleted
m (added a comma.)
(Added XPL0 example.)
Line 782: Line 782:


49 such primes found.
49 such primes found.
</pre>

=={{header|XPL0}}==
Find primes where the difference between the current one and a following one is a perfect square.
<lang XPL0>func IsPrime(N); \Return 'true' if N is a prime number
int N, I;
[if N <= 1 then return false;
for I:= 2 to sqrt(N) do
if rem(N/I) = 0 then return false;
return true;
];

int Count, P, Q;
[Count:= 0;
P:= 2; Q:= 3;
repeat if IsPrime(Q) then
[if sq(sqrt(Q-P)) = Q-P then
[IntOut(0, P);
P:= Q;
Count:= Count+1;
if rem(Count/10) then ChOut(0, 9\tab\) else CrLf(0);
];
];
Q:= Q+2;
until P >= 16000;
CrLf(0);
IntOut(0, Count);
Text(0, " such primes found below 16000.
");
]</lang>

{{out}}
<pre>
2 3 7 11 47 83 227 263 587 911
947 983 1019 1163 1307 1451 1487 1523 1559 2459
3359 4259 4583 5483 5519 5843 5879 6203 6779 7103
7247 7283 7607 7643 8219 8363 10667 11243 11279 11423
12323 12647 12791 13367 13691 14591 14627 14771 15671
49 such primes found below 16000.
</pre>
</pre>