Jump to content

Magnanimous numbers: Difference between revisions

add Cowgol
(Add CLU)
(add Cowgol)
Line 619:
391-400:
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081</pre>
 
=={{header|Cowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub prime(n: uint32): (r: uint32) is
r := 0;
if n <= 4 or n & 1 == 0 or n % 3 == 0 then
if n == 2 or n == 3 then
r := 1;
end if;
return;
end if;
 
var d: uint32 := 5;
while d*d <= n loop
if n % d == 0 then return; end if;
d := d+2;
if n % d == 0 then return; end if;
d := d+4;
end loop;
r := 1;
end sub;
 
sub magnanimous(n: uint32): (r: uint32) is
r := 1;
var left: uint32 := n;
var right: uint32 := 0;
var shift: uint32 := 1;
 
while left >= 10 loop
right := right + (left % 10) * shift;
shift := shift * 10;
left := left / 10;
if prime(left + right) == 0 then
r := 0;
break;
end if;
end loop;
end sub;
 
var i: uint16 := 0;
var n: uint32 := 0;
 
while i <= 400 loop
while magnanimous(n) == 0 loop n := n+1; end loop;
i := i + 1;
 
if i == 1 then print("1 - 45:\n");
elseif i == 241 then print("241 - 250:\n");
elseif i == 391 then print("390 - 400:\n");
end if;
 
if i<=45 or (i>240 and i<=250) or (i>390 and i<=400) then
print_i32(n);
if i % 5 == 0 then print_nl();
else print_char('\t');
end if;
end if;
n := n + 1;
end loop;</syntaxhighlight>
{{out}}
<pre>1 - 45:
0 1 2 3 4
5 6 7 8 9
11 12 14 16 20
21 23 25 29 30
32 34 38 41 43
47 49 50 52 56
58 61 65 67 70
74 76 83 85 89
92 94 98 101 110
241 - 250:
17992 19972 20209 20261 20861
22061 22201 22801 22885 24407
390 - 400:
486685 488489 515116 533176 551558
559952 595592 595598 600881 602081</pre>
 
 
=={{header|Delphi}}==
2,115

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.