Largest difference between adjacent primes: Difference between revisions

Content added Content deleted
(Added Algol 68)
(Added XPL0 example.)
Line 294: Line 294:
Under 100,000,000: 47,326,913 - 47,326,693 = 220
Under 100,000,000: 47,326,913 - 47,326,693 = 220
Under 1,000,000,000: 436,273,291 - 436,273,009 = 282
Under 1,000,000,000: 436,273,291 - 436,273,009 = 282
</pre>

=={{header|XPL0}}==
<lang XPL0>def Size = 1_000_000_000/2; \sieve for odd numbers
int Prime, I, K;
char Flags;
int Limit, TenToThe, Max, Gap, I0, Prime0, Prime1;
[Flags:= MAlloc(Size+1); \(heap only provides 64 MB)
for I:= 0 to Size do \set flags all true
Flags(I):= true;
for I:= 0 to Size do
if Flags(I) then \found a prime
[Prime:= I+I+3;
K:= I+Prime; \first multiple to strike off
while K <= Size do \strike off all multiples
[Flags(K):= false;
K:= K+Prime;
];
];
Text(0, "Largest difference between adjacent primes under:
");
Limit:= 10;
for TenToThe:= 1 to 9 do
[Max:= 0; I0:= 0;
for I:= 0 to Limit/2-3 do
[if Flags(I) then \odd prime
[Gap:= I - I0;
if Gap > Max then
[Max:= Gap;
Prime0:= I0*2 + 3;
Prime1:= I *2 + 3;
];
I0:= I;
];
];
IntOut(0, Limit); Text(0, " is ");
IntOut(0, Prime1); Text(0, " - ");
IntOut(0, Prime0); Text(0, " = ");
IntOut(0, Max*2); CrLf(0);
Limit:= Limit*10;
];
]</lang>

{{out}}
<pre>
Largest difference between adjacent primes under:
10 is 5 - 3 = 2
100 is 97 - 89 = 8
1000 is 907 - 887 = 20
10000 is 9587 - 9551 = 36
100000 is 31469 - 31397 = 72
1000000 is 492227 - 492113 = 114
10000000 is 4652507 - 4652353 = 154
100000000 is 47326913 - 47326693 = 220
1000000000 is 436273291 - 436273009 = 282
</pre>
</pre>