Magnanimous numbers: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add Draco) |
Not a robot (talk | contribs) (Add SETL) |
||
Line 3,546: | Line 3,546: | ||
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081 |
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081 |
||
</pre> |
</pre> |
||
=={{header|SETL}}== |
|||
<syntaxhighlight lang="setl">program magnanimous; |
|||
n := -1; |
|||
loop for i in [1..400] do |
|||
loop until magnanimous(n) do n +:= 1; end loop; |
|||
case i of |
|||
(1): print("1 - 45:"); |
|||
(241): print; print("241 - 250:"); |
|||
(391): print; print("391 - 400:"); |
|||
end case; |
|||
if i in [1..45] or i in [241..250] or i in [391..400] then |
|||
putchar(lpad(str n, 7)); |
|||
if i mod 5 = 0 then print; end if; |
|||
end if; |
|||
end loop; |
|||
proc magnanimous(n); |
|||
return forall k in splitsums(n) | prime(k); |
|||
end proc; |
|||
proc splitsums(n); |
|||
s := str n; |
|||
return [val s(..i) + val s(i+1..) : i in [1..#s-1]]; |
|||
end proc; |
|||
proc prime(n); |
|||
if n<2 then return false; |
|||
elseif even n then return(n = 2); |
|||
elseif n mod 3=0 then return(n = 3); |
|||
else |
|||
d := 5; |
|||
loop while d*d <= n do |
|||
if n mod d=0 then return false; end if; |
|||
d +:= 2; |
|||
if n mod d=0 then return false; end if; |
|||
d +:= 4; |
|||
end loop; |
|||
return true; |
|||
end if; |
|||
end proc; |
|||
end program;</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 |
|||
391 - 400: |
|||
486685 488489 515116 533176 551558 |
|||
559952 595592 595598 600881 602081</pre> |
|||
=={{header|Sidef}}== |
=={{header|Sidef}}== |