Safe and Sophie Germain primes: Difference between revisions
Content deleted Content added
Added Easylang |
Not a robot (talk | contribs) Add Cowgol |
||
Line 127:
1049 1103 1223 1229 1289 1409 1439 1451 1481 1499
</pre>
=={{header|Cowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
sub prime(n: uint16): (r: uint8) is
if n<2 then r := 0; return; end if;
if n==2 then r := 1; return; end if;
if n%2==0 then r := 0; return; end if;
var d: uint16 := 3;
while d*d <= n loop
if n%d == 0 then r := 0; return; end if
d := d + 2;
end loop;
r := 1;
end sub;
sub sophie_germain(n: uint16): (r: uint8) is
r := 0;
if prime(n) != 0 and prime(2*n+1) != 0 then
r := 1;
end if;
end sub;
var n: uint16 := 1;
var amount: uint16 := 50;
while amount > 0 loop
if sophie_germain(n) != 0 then
print_i16(n);
if amount % 10 == 1
then print_nl();
else print_char('\t');
end if;
amount := amount - 1;
end if;
n := n + 1;
end loop;
print_nl();</syntaxhighlight>
{{out}}
<pre>2 3 5 11 23 29 41 53 83 89
113 131 173 179 191 233 239 251 281 293
359 419 431 443 491 509 593 641 653 659
683 719 743 761 809 911 953 1013 1019 1031
1049 1103 1223 1229 1289 1409 1439 1451 1481 1499</pre>
=={{header|Delphi}}==
Line 192 ⟶ 235:
</pre>
=={{header|EasyLang}}==
|