De Polignac numbers: Difference between revisions

Content added Content deleted
(Added Wren)
(Added XPL0 example.)
Line 198: Line 198:


Ten thousandth: 273,421
Ten thousandth: 273,421
</pre>

=={{header|XPL0}}==
Slow. Takes 225 seconds on Pi4.
<syntaxhighlight lang "XPL0">func IsPrime(N); \Return 'true' if N is prime
int N, I;
[if N <= 2 then return N = 2;
if (N&1) = 0 then \even >2\ return false;
for I:= 3 to sqrt(N) do
[if rem(N/I) = 0 then return false;
I:= I+1;
];
return true;
];

func IsDePolignac(N); \Return 'true' if N is a de Polignac number
int N, P, T;
[for P:= N-1 downto 2 do
if IsPrime(P) then
[T:= 1;
repeat if T+P = N then return false;
T:= T<<1;
until T+P > N;
];
return true;
];

int N, C;
[Format(5, 0);
N:= 1; C:= 0;
loop [if IsDePolignac(N) then
[C:= C+1;
if C<=50 or C=1000 or C=10000 then
[RlOut(0, float(N));
if rem(C/10) = 0 then CrLf(0);
if C = 10000 then quit;
];
];
N:= N+2;
];
]</syntaxhighlight>
{{out}}
<pre>
1 127 149 251 331 337 373 509 599 701
757 809 877 905 907 959 977 997 1019 1087
1199 1207 1211 1243 1259 1271 1477 1529 1541 1549
1589 1597 1619 1649 1657 1719 1759 1777 1783 1807
1829 1859 1867 1927 1969 1973 1985 2171 2203 2213
31941
273421
</pre>
</pre>