Cousin primes: Difference between revisions

Ada version
(Add BCPL)
(Ada version)
Line 18:
:*   the MathWorld entry:   [https://mathworld.wolfram.com/CousinPrimes.html cousin primes].
<br><br>
 
=={{header|Ada}}==
<lang Ada>with Ada.Text_Io;
 
procedure Cousin_Primes is
 
type Number is new Long_Integer range 0 .. Long_Integer'Last;
package Number_Io is new Ada.Text_Io.Integer_Io (Number);
 
function Is_Prime (A : Number) return Boolean is
D : Number;
begin
if A < 2 then return False; end if;
if A in 2 .. 3 then return True; end if;
if A mod 2 = 0 then return False; end if;
if A mod 3 = 0 then return False; end if;
D := 5;
while D * D <= A loop
if A mod D = 0 then
return False;
end if;
D := D + 2;
if A mod D = 0 then
return False;
end if;
D := D + 4;
end loop;
return True;
end Is_Prime;
 
use Ada.Text_Io;
Count : Natural := 0;
begin
for N in Number range 1 .. 999 - 4 loop
if Is_Prime (N) and then Is_Prime (N + 4) then
Count := Count + 1;
Put("[");
Number_Io.Put (N, Width => 3); Put (",");
Number_Io.Put (N + 4, Width => 3);
Put("] ");
if Count mod 8 = 0 then
New_Line;
end if;
end if;
end loop;
New_Line;
Put_Line (Count'Image & " pairs.");
end Cousin_Primes;</lang>
{{out}}
<pre>[ 3, 7] [ 7, 11] [ 13, 17] [ 19, 23] [ 37, 41] [ 43, 47] [ 67, 71] [ 79, 83]
[ 97,101] [103,107] [109,113] [127,131] [163,167] [193,197] [223,227] [229,233]
[277,281] [307,311] [313,317] [349,353] [379,383] [397,401] [439,443] [457,461]
[463,467] [487,491] [499,503] [613,617] [643,647] [673,677] [739,743] [757,761]
[769,773] [823,827] [853,857] [859,863] [877,881] [883,887] [907,911] [937,941]
[967,971]
41 pairs.</pre>
 
=={{header|ALGOL 68}}==
210

edits