Magnanimous numbers: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (add Modula-2) |
Not a robot (talk | contribs) (add BCPL) |
||
Line 364: | Line 364: | ||
{{out}} |
{{out}} |
||
<pre>Same as FreeBASIC entry.</pre> |
<pre>Same as FreeBASIC entry.</pre> |
||
=={{header|BCPL}}== |
|||
<syntaxhighlight lang="bcpl">get "libhdr" |
|||
let prime(n) = valof |
|||
$( let d = 5 |
|||
if n<2 resultis false |
|||
if n rem 2=0 resultis n=2 |
|||
if n rem 3=0 resultis n=3 |
|||
while d*d <= n |
|||
$( if n rem d=0 resultis false |
|||
d := d+2 |
|||
if n rem d=0 resultis false |
|||
d := d+4 |
|||
$) |
|||
resultis true |
|||
$) |
|||
let magnanimous(n) = valof |
|||
$( let left = n and right = 0 and shift = 1 |
|||
while left >= 10 |
|||
$( right := right + (left rem 10) * shift |
|||
shift := shift * 10 |
|||
left := left / 10 |
|||
unless prime(left + right) resultis false |
|||
$) |
|||
resultis true |
|||
$) |
|||
let start() be |
|||
$( let n = -1 |
|||
for i = 1 to 250 |
|||
$( n := n+1 repeatuntil magnanimous(n) |
|||
if i=1 then writes("1 - 45:*N") |
|||
if i=241 then writes("241 - 250:*N") |
|||
if 0<i<=45 | 240<i<=250 |
|||
$( writed(n, 7) |
|||
if i rem 5=0 then wrch('*N') |
|||
$) |
|||
$) |
|||
$)</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</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |