Cousin primes: Difference between revisions

Add Cowgol
(Add BASIC)
(Add Cowgol)
Line 110:
937 941
967 971
There are 41 cousin prime pairs below 1000</pre>
 
=={{header|Cowgol}}==
<lang cowgol>include "cowgol.coh";
 
const LIMIT := 1000;
var sieve: uint8[LIMIT + 1];
MemZero(&sieve[0], @bytesof sieve);
 
var p: @indexof sieve := 2;
 
loop
var n := p*p;
if n >= LIMIT then break; end if;
if sieve[p] == 0 then
while n < LIMIT loop
sieve[n] := 1;
n := n + p;
end loop;
end if;
p := p + 1;
end loop;
 
var count: uint8 := 0;
n := 2;
while n < LIMIT-4 loop
if sieve[n] + sieve[n+4] == 0 then
count := count + 1;
print_i32(n as uint32);
print_char('\t');
print_i32(n as uint32+4);
print_nl();
end if;
n := n + 1;
end loop;
 
print("There are ");
print_i8(count);
print(" cousin prime pairs below ");
print_i16(LIMIT);
print_nl();</lang>
 
{{out}}
 
<pre style="height: 14em;">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
There are 41 cousin prime pairs below 1000</pre>
 
2,094

edits