Magnanimous numbers: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(27 intermediate revisions by 14 users not shown)
Line 33:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">BEGIN # find some magnanimous numbers - numbers where inserting a + between any #
# digits ab=nd evaluatinf the sum results in a prime in all cases #
# returns the first n magnanimous numbers #
Line 78:
print magnanimous( m, 241, 250, "Magnanimous numbers 241-250" );
print magnanimous( m, 391, 400, "Magnanimous numbers 391-400" )
END</langsyntaxhighlight>
{{out}}
<pre>
Line 90:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin
% find some Magnanimous numbers - numbers where inserting a "+" between %
% any two of the digits and evaluating the sum results in a prime number %
Line 228:
write( "Last magnanimous number found: ", mPos, " = ", lastM )
end
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 240:
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081
Last magnanimous number found: 434 = 999994
</pre>
 
 
=={{header|Amazing Hopper}}==
<syntaxhighlight lang="c">
#include <basico.h>
 
#proto encontrarunMagnanimouspara(_X_)
#synon _encontrarunMagnanimouspara siencontréunMagnanimousen
 
algoritmo
 
decimales '0'
res={}, i=0
iterar grupo( ++i, #(length(res)<400), \
i, meter según ( si encontré un Magnanimous en 'i', res ))
 
#(utf8("Primeros 45 números magnánimos:\n")), #(res[1:45])
#(utf8("\n\nNúmeros magnánimos 241 - 250:\n")), #(res[241:250])
#(utf8("\n\nNúmeros magnánimos 391 - 400:\n")), #(res[391:400]), NL
luego imprime esto
 
terminar
 
subrutinas
 
encontrar un Magnanimous para(n)
tn=n, d=0, i=0, pd=0
iterar
último dígito de 'tn', mover a 'd,tn'
cuando ' tn ' { #( pd += ( d * 10^i ) ) }
mientras ' #( tn && is prime(tn+pd) ); ++i '
 
retornar ' #(not(tn)) '
</syntaxhighlight>
{{out}}
<pre>
Primeros 45 números magnánimos:
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
 
Números magnánimos 241 - 250:
17992,19972,20209,20261,20861,22061,22201,22801,22885,24407
 
Números magnánimos 391 - 400:
486685,488489,515116,533176,551558,559952,595592,595598,600881,602081
</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f MAGNANIMOUS_NUMBERS.AWK
# converted from C
Line 286 ⟶ 332:
printf("\n")
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 293 ⟶ 339:
391-400: 486685 488489 515116 533176 551558 559952 595592 595598 600881 602081
</pre>
 
=={{header|BASIC}}==
<syntaxhighlight lang="gwbasic">10 DEFINT A-Z
20 L = N : R = 0 : S = 1
30 IF L < 10 GOTO 140
40 R = R + (L MOD 10) * S
50 L = L \ 10
60 S = S * 10
70 P = R + L
80 IF P = 1 GOTO 120 ELSE FOR D = 2 TO SQR(P)
90 IF P MOD D = 0 GOTO 120
100 NEXT D
110 GOTO 30
120 N = N + 1
130 GOTO 20
140 I = I + 1
150 IF I = 1 THEN PRINT "1 - 45:" ELSE IF I = 241 THEN PRINT "241 - 250:"
160 IF I <= 45 OR I > 240 THEN PRINT N,
170 N = N + 1
180 IF I < 250 GOTO 20
190 END</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|BASIC256}}==
<syntaxhighlight lang="vb">#include "isprime.kbs"
 
dim magn(400)
n = 10
for i = 0 to 9
magn[i] = i #all single digit ints are magnanimous by definition
next i
 
while i < 400
n += 1
ns = string(n)
for j = 1 to length(ns)-1
lefty = left(ns, j)
righty = right(ns, length(ns)-j)
if not isPrime(int(lefty) + int(righty)) then continue while
next j
magn[i] = n
i += 1
end while
 
for i = 0 to 44
print i+1, magn[i]
next i
 
for i =240 to 249
print i+1, magn[i]
next i
 
for i = 390 to 399
print i+1, magn[i]
next i
end</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> DIM Sieve% 1E5
Prime%=2
WHILE Prime%^2 < 1E5
FOR S%=Prime%*2 TO 1E5 STEP Prime% Sieve%?S%=1 NEXT
REPEAT Prime%+=1 UNTIL Sieve%?Prime%=0
ENDWHILE
Sieve%?1=1
 
PRINT "First 45 magnanimous numbers"
REPEAT
IF M% > 9 THEN
FOR I%=LOGM% TO 1 STEP -1
IF Sieve%?((M% DIV 10^I%) + (M% MOD 10^I%)) EXIT FOR
NEXT
ENDIF
IF I% == 0 THEN
N%+=1
IF N% == 240 OR N% == 390 PRINT '"Magnanimous numbers ";N% + 1 "-";N% + 10
IF N% < 46 OR (N% > 240 AND N% < 251) OR (N% > 390 AND N% < 401) PRINT;M% " ";
ENDIF
M%+=1
UNTIL N% > 400</syntaxhighlight>
{{out}}
<pre>First 45 magnanimous numbers
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
Magnanimous numbers 241-250
17992 19972 20209 20261 20861 22061 22201 22801 22885 24407
Magnanimous numbers 391-400
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081</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}}==
{{trans|Go}}
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <string.h>
 
Line 383 ⟶ 587:
list_mags(391, 400, 1, 10);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 400 ⟶ 604:
 
=={{header|C#|CSharp}}==
<langsyntaxhighlight lang="csharp">using System; using static System.Console;
 
class Program {
Line 424 ⟶ 628:
if (c == 240) WriteLine ("\n\n241st through 250th{0}", mn);
if (c == 390) WriteLine ("\n\n391st through 400th{0}", mn); } }
}</langsyntaxhighlight>
 
{{out}}
Line 439 ⟶ 643:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iomanip>
#include <iostream>
 
Line 500 ⟶ 704:
std::cout << '\n';
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 515 ⟶ 719:
486685, 488489, 515116, 533176, 551558, 559952, 595592, 595598, 600881, 602081
</pre>
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">prime = proc (n: int) returns (bool)
if n < 2 then return(false) end
if n//2 = 0 then return(n=2) end
if n//3 = 0 then return(n=3) end
d: int := 5
while d*d <= n do
if n//d = 0 then return(false) end
d := d+2
if n//d = 0 then return(false) end
d := d+4
end
return(true)
end prime
 
sum_parts = iter (l: int) yields (int)
r: int := 0
s: int := 0
while l >= 10 do
r := r + (l // 10) * 10 ** s
s := s + 1
l := l / 10
yield(l + r)
end
end sum_parts
 
magnanimous = proc (n: int) returns (bool)
for s: int in sum_parts(n) do
if ~prime(s) then return(false) end
end
return(true)
end magnanimous
 
start_up = proc ()
po: stream := stream$primary_output()
n: int := 0
i: int := 0
c: int := 0
 
while i <= 400 do
while ~magnanimous(n) do n := n+1 end
i := i+1
 
if i=1 then stream$putl(po, "1-45:") c := 0
elseif i=241 then stream$putl(po, "\n241-250:") c := 0
elseif i=391 then stream$putl(po, "391-400:") c := 0
end
 
if i <= 45 cor (i > 240 cand i <= 250) cor (i > 390 cand i <= 400) then
stream$putright(po, int$unparse(n), 7)
c := c+1
if c = 10 then stream$putl(po, "") c := 0 end
end
n := n+1
end
end start_up</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|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}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
Highly modular code breaks the problem down into its basic components, which makes the problem easier to solve conceptually, easier to debug and enhance.
 
<syntaxhighlight lang="Delphi">
 
 
function IsPrime(N: int64): boolean;
{Fast, optimised prime test}
var I,Stop: int64;
begin
if (N = 2) or (N=3) then Result:=true
else if (n <= 1) or ((n mod 2) = 0) or ((n mod 3) = 0) then Result:= false
else
begin
I:=5;
Stop:=Trunc(sqrt(N+0.0));
Result:=False;
while I<=Stop do
begin
if ((N mod I) = 0) or ((N mod (I + 2)) = 0) then exit;
Inc(I,6);
end;
Result:=True;
end;
end;
 
function IsMagnanimous(N: Integer): boolean;
var S,S1,S2: string;
var I,I1,I2: integer;
begin
Result:=True;
if N<10 then exit;
Result:=False;
S:=IntToStr(N);
for I:=2 to Length(S) do
begin
S1:=Copy(S,1,I-1);
S2:=Copy(S,I,(Length(S)-I)+1);
I1:=StrToInt(S1);
I2:=StrToInt(S2);
if not IsPrime(I1+I2) then exit;
end;
Result:=True;
end;
 
procedure MagnanimousRange(Memo: TMemo; Start,Stop: integer);
var I,MagCnt,ItemCnt: integer;
var S: string;
begin
S:='';
MagCnt:=0;
ItemCnt:=0;
for I:=0 to High(Integer) do
if IsMagnanimous(I) then
begin
Inc(MagCnt);
if MagCnt>=Start then
begin
if MagCnt>Stop then break;
S:=S+Format('%12d',[I]);
Inc(ItemCnt);
if (ItemCnt mod 5)=0 then S:=S+#$0D#$0A;
end;
end;
Memo.Lines.Add(S);
end;
 
procedure MagnanimousNumbers(Memo: TMemo);
begin
Memo.Lines.Add('First 45 Magnanimous Numbers');
MagnanimousRange(Memo,0,45);
Memo.Lines.Add('Magnanimous Numbers 241 through 250');
MagnanimousRange(Memo,241,250);
Memo.Lines.Add('Magnanimous Numbers 391 through 400');
MagnanimousRange(Memo,391,400);
end;
 
</syntaxhighlight>
{{out}}
<pre>
First 45 Magnanimous Numbers
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
 
Magnanimous Numbers 241 through 250
17992 19972 20209 20261 20861
22061 22201 22801 22885 24407
 
Magnanimous Numbers 391 through 400
486685 488489 515116 533176 551558
559952 595592 595598 600881 602081
</pre>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc isprime(word n) bool:
word d;
bool prime;
if n<2 then false
elif n%2=0 then n=2
elif n%3=0 then n=3
else
prime := true;
d := 5;
while prime and d*d <= n do
if n%d=0 then prime := false fi;
d := d+2;
if n%d=0 then prime := false fi;
d := d+4
od;
prime
fi
corp
 
proc magnanimous(word n) bool:
word left, right, shift;
bool magn;
left := n;
right := 0;
shift := 1;
magn := true;
while magn and left >= 10 do
right := right + (left % 10) * shift;
shift := shift * 10;
left := left / 10;
magn := magn and isprime(left + right)
od;
magn
corp
 
proc main() void:
word n, i;
n := 0;
for i from 1 upto 250 do
while not magnanimous(n) do n := n+1 od;
if i=1 then writeln("1 - 45:") fi;
if i=241 then writeln("241 - 250:") fi;
if i<=45 or i>=241 then
write(n:7);
if i%5 = 0 then writeln() fi
fi;
n := n+1
od
corp</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|EasyLang}}==
{{trans|AWK}}
<syntaxhighlight>
fastfunc isprim num .
if num < 2
return 0
.
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
func ismagnan n .
if n < 10
return 1
.
p = 10
repeat
q = n div p
r = n mod p
if isprim (q + r) = 0
return 0
.
until q < 10
p *= 10
.
return 1
.
proc magnan start stop . .
write start & "-" & stop & ":"
while count < stop
if ismagnan i = 1
count += 1
if count >= start
write " " & i
.
.
i += 1
.
print ""
.
magnan 1 45
magnan 241 250
magnan 391 400
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
===The function===
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_function Extensible Prime Generator (F#)]
<langsyntaxhighlight lang="fsharp">
// Generate Magnanimous numbers. Nigel Galloway: March 20th., 2020
let rec fN n g = match (g/n,g%n) with
Line 526 ⟶ 1,093:
|_ -> false
let Magnanimous = let Magnanimous = fN 10 in seq{yield! {0..9}; yield! Seq.initInfinite id |> Seq.skip 10 |> Seq.filter Magnanimous}
</syntaxhighlight>
</lang>
===The Tasks===
;First 45
 
<langsyntaxhighlight lang="fsharp">
Magnanimous |> Seq.take 45 |> Seq.iter (printf "%d "); printfn ""
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 539 ⟶ 1,106:
;Magnanimous[241] to Magnanimous[250]
 
<langsyntaxhighlight lang="fsharp">
Magnanimous |> Seq.skip 240 |> Seq.take 10 |> Seq.iter (printf "%d "); printfn "";;
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 548 ⟶ 1,115:
;Magnanimous[391] to Magnanimous[400]
 
<langsyntaxhighlight lang="fsharp">
Magnanimous |> Seq.skip 390 |> Seq.take 10 |> Seq.iter (printf "%d "); printfn "";;
</syntaxhighlight>
</lang>
{{out}}
<pre>
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081
</pre>
 
=={{header|Factor}}==
{{trans|Julia}}
{{works with|Factor|0.99 2020-01-23}}
<langsyntaxhighlight lang="factor">USING: grouping io kernel lists lists.lazy math math.functions
math.primes math.ranges prettyprint sequences ;
 
Line 576 ⟶ 1,144:
[ "241st through 250th magnanimous numbers" print 240 250 show ]
[ "391st through 400th magnanimous numbers" print 390 400 show ]
tri</langsyntaxhighlight>
{{out}}
<pre>
Line 590 ⟶ 1,158:
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
#include "isprime.bas"
 
dim as uinteger magn(0 to 399), i, n=10, j
dim as string ns, lefty, righty
for i = 0 to 9
magn(i) = i 'all single digit ints are magnanimous by definition
next i
 
while i<400
n += 1
ns = str(n)
for j = 1 to len(ns)-1
lefty = left(ns, j)
righty = right(ns, len(ns)-j)
if not isprime( val(lefty) + val(righty) ) then continue while
next j
magn(i) = n
i+=1
wend
 
for i=0 to 44
print i+1,magn(i)
next i
 
for i=240 to 249
print i+1,magn(i)
next i
 
for i=390 to 399
print i+1,magn(i)
next i
</syntaxhighlight>
{{out}}
<pre>1 0
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 11
12 12
13 14
14 16
15 20
16 21
17 23
18 25
19 29
20 30
21 32
22 34
23 38
24 41
25 43
26 47
27 49
28 50
29 52
30 56
31 58
32 61
33 65
34 67
35 70
36 74
37 76
38 83
39 85
40 89
41 92
42 94
43 98
44 101
45 110
241 17992
242 19972
243 20209
244 20261
245 20861
246 22061
247 22201
248 22801
249 22885
250 24407
391 486685
392 488489
393 515116
394 533176
395 551558
396 559952
397 595592
398 595598
399 600881
400 602081</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 681 ⟶ 1,350:
listMags(241, 250, 1, 10)
listMags(391, 400, 1, 10)
}</langsyntaxhighlight>
 
{{out}}
<pre>
Line 695 ⟶ 1,363:
391st through 400th magnanimous numbers:
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081
</pre>
 
=={{header|GW-BASIC}}==
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
<syntaxhighlight lang="qbasic">100 DEFINT A-Z
110 CLS
120 LET L = N
130 LET R = 0
140 LET S = 1
150 IF L < 10 THEN GOTO 300
160 LET R = R+(L MOD 10)*S
170 LET L = L\10
180 LET S = S*10
190 LET P = R+L
200 IF P = 1 THEN GOTO 280 ELSE FOR D = 2 TO SQR(P)
210 IF P MOD D = 0 THEN GOTO 280
250 NEXT D
270 GOTO 150
280 LET N = N+1
290 GOTO 120
300 LET I = I+1
310 IF I = 1 THEN PRINT "1 - 45:" ELSE IF I = 241 THEN PRINT : PRINT "241 - 250:"
320 IF I <= 45 OR I > 240 THEN PRINT N,
330 LET N = N+1
340 IF I < 250 THEN GOTO 120
350 PRINT
360 END</syntaxhighlight>
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">import Data.List.Split ( chunksOf )
import Data.List ( (!!) )
 
isPrime :: Int -> Bool
isPrime n
|n == 2 = True
|n == 1 = False
|otherwise = null $ filter (\i -> mod n i == 0 ) [2 .. root]
where
root :: Int
root = floor $ sqrt $ fromIntegral n
isMagnanimous :: Int -> Bool
isMagnanimous n = all isPrime $ map (\p -> fst p + snd p ) numberPairs
where
str:: String
str = show n
splitStrings :: [(String , String)]
splitStrings = map (\i -> splitAt i str) [1 .. length str - 1]
numberPairs :: [(Int , Int)]
numberPairs = map (\p -> ( read $ fst p , read $ snd p )) splitStrings
 
printInWidth :: Int -> Int -> String
printInWidth number width = replicate ( width - l ) ' ' ++ str
where
str :: String
str = show number
l :: Int
l = length str
 
solution :: [Int]
solution = take 400 $ filter isMagnanimous [0 , 1 ..]
 
main :: IO ( )
main = do
let numbers = solution
numberlines = chunksOf 10 $ take 45 numbers
putStrLn "First 45 magnanimous numbers:"
mapM_ (\li -> putStrLn (foldl1 ( ++ ) $ map (\n -> printInWidth n 6 )
li )) numberlines
putStrLn "241'st to 250th magnanimous numbers:"
putStr $ show ( numbers !! 240 )
putStrLn ( foldl1 ( ++ ) $ map(\n -> printInWidth n 8 ) $ take 9 $
drop 241 numbers )
putStrLn "391'st to 400th magnanimous numbers:"
putStr $ show ( numbers !! 390 )
putStrLn ( foldl1 ( ++ ) $ map(\n -> printInWidth n 8 ) $ drop 391 numbers)</syntaxhighlight>
{{out}}
<pre>First 45 magnanimous numbers:
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'st to 250th magnanimous numbers:
17992 19972 20209 20261 20861 22061 22201 22801 22885 24407
391'st to 400th magnanimous numbers:
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081
</pre>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">
import java.util.ArrayList;
import java.util.List;
Line 884 ⟶ 1,640:
 
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 923 ⟶ 1,679:
 
'''Preliminaries'''
<langsyntaxhighlight lang="jq"># To take advantage of gojq's arbitrary-precision integer arithmetic:
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);
 
def divrem($x; $y):
[$x/$y|floor, $x % $y];
</syntaxhighlight>
</lang>
'''The Task'''
<syntaxhighlight lang="jq">
<lang jq>
def ismagnanimous:
. as $n
Line 949 ⟶ 1,705:
| "First 45 magnanimous numbers:", .[:45],
"\n241st through 250th magnanimous numbers:", .[241:251],
"\n391st through 400th magnanimous numbers:", .[391:]</langsyntaxhighlight>
{{out}}
<pre>
Line 964 ⟶ 1,720:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Primes
 
function ismagnanimous(n)
Line 990 ⟶ 1,746:
println("\n241st through 250th magnanimous numbers:\n", mag400[241:250])
println("\n391st through 400th magnanimous numbers:\n", mag400[391:400])
</langsyntaxhighlight>{{out}}
<pre>
First 45 magnanimous numbers:
Line 1,002 ⟶ 1,758:
[486685, 488489, 515116, 533176, 551558, 559952, 595592, 595598, 600881, 602081]
</pre>
 
=={{header|Lambdatalk}}==
{{trans|Phix}}
<syntaxhighlight lang="scheme">
 
{def isprime
{def isprime.loop
{lambda {:n :m :i}
{if {> :i :m}
then true
else {if {= {% :n :i} 0}
then false
else {isprime.loop :n :m {+ :i 2}}
}}}}
{lambda {:n}
{if {= :n 1}
then false
else {if {or {= :n 2} {= :n 3} {= :n 5} {= :n 7}}
then true
else {if {or {< : n 2} {= {% :n 2} 0}}
then false
else {isprime.loop :n {sqrt :n} 3}
}}}}}
-> isprime
 
{def magnanimous
{def magnanimous.loop
{lambda {:n :p :r}
{if {>= :n 10}
then {let { {:n {floor {/ :n 10}}}
{:p :p}
{:r {+ :r {* {% :n 10} :p}}}
} {if {not {isprime {+ :n :r}}}
then false
else {magnanimous.loop :n {* :p 10} :r} }
}
else true }}}
{lambda {:n}
{magnanimous.loop :n 1 0} }}
-> magnanimous
{def mags
{lambda {:n}
{S.last
{S.map {{lambda {:a :i}
{if {magnanimous :i} then {A.addlast! :i :a} else}}
{A.new}}
{S.serie 0 :n}}}}}
-> mags
 
{A.slice 0 45 {mags 110}}
-> [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]
{A.slice 240 250 {mags 30000}}
->
[17992,19972,20209,20261,20861,22061,22201,22801,22885,24407]
 
{A.slice 390 400 {mags 700000}}
->
[486685,488489,515116,533176,551558,559952,595592,595598,600881,602081]
 
time of CPU in milliseconds
iPadPro MacBookAir MacBookPro
[0,45] 30 15 12
[240,250] 2430 5770 3650
[390,400] 117390 284230 213210
 
</syntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">Clear[MagnanimousNumberQ]
MagnanimousNumberQ[Alternatives @@ Range[0, 9]] = True;
MagnanimousNumberQ[n_Integer] := AllTrue[Range[IntegerLength[n] - 1], PrimeQ[Total[FromDigits /@ TakeDrop[IntegerDigits[n], #]]] &]
Line 1,010 ⟶ 1,834:
sel[[;; 45]]
sel[[241 ;; 250]]
sel[[391 ;; 400]]</langsyntaxhighlight>
{{out}}
<pre>{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}
{17992,19972,20209,20261,20861,22061,22201,22801,22885,24407}
{486685,488489,515116,533176,551558,559952,595592,595598,600881,602081}</pre>
 
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE MagnanimousNumbers;
FROM InOut IMPORT WriteString, WriteCard, WriteLn;
 
VAR n, i: CARDINAL;
 
PROCEDURE prime(n: CARDINAL): BOOLEAN;
VAR d: CARDINAL;
BEGIN
IF n<2 THEN RETURN FALSE END;
IF n MOD 2 = 0 THEN RETURN n = 2 END;
IF n MOD 3 = 0 THEN RETURN n = 3 END;
d := 5;
WHILE d*d <= n DO
IF n MOD d = 0 THEN RETURN FALSE END;
INC(d, 2);
IF n MOD d = 0 THEN RETURN FALSE END;
INC(d, 4)
END;
RETURN TRUE
END prime;
 
PROCEDURE magnanimous(n: CARDINAL): BOOLEAN;
VAR left, right, shift: CARDINAL;
BEGIN
left := n;
right := 0;
shift := 1;
WHILE left >= 10 DO
INC(right, (left MOD 10) * shift);
shift := shift * 10;
left := left DIV 10;
IF NOT prime(left + right) THEN RETURN FALSE END
END;
RETURN TRUE
END magnanimous;
 
BEGIN
n := 0;
FOR i := 1 TO 250 DO
WHILE NOT magnanimous(n) DO INC(n) END;
 
IF i=1 THEN WriteString("1 - 45:"); WriteLn
ELSIF i=240 THEN WriteString("241 - 250:"); WriteLn
END;
 
IF (i <= 45) OR (i > 240) THEN
WriteCard(n, 7);
IF i MOD 5 = 0 THEN WriteLn END
END;
INC(n)
END
END MagnanimousNumbers.</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|Nim}}==
<langsyntaxhighlight Nimlang="nim">func isPrime(n: Natural): bool =
if n < 2: return
if n mod 2 == 0: return n == 2
Line 1,064 ⟶ 1,956:
 
elif i > 400:
break</langsyntaxhighlight>
 
{{out}}
Line 1,075 ⟶ 1,967:
391st through 400th magnanimous numbers:
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081</pre>
 
=={{header|Pascal}}==
{{works with|Free Pascal}}
Line 1,080 ⟶ 1,973:
Eliminating all numbers, which would sum to 5 in the last digit.<br>
On TIO.RUN found all til 569 84448000009 0.715 s
<langsyntaxhighlight lang="pascal">program Magnanimous;
//Magnanimous Numbers
//algorithm find only numbers where all digits are even except the last
Line 1,462 ⟶ 2,355:
readln;
{$ENDIF}
end.</langsyntaxhighlight>
{{out}}
<pre style="height:180px">
Line 2,047 ⟶ 2,940:
{{trans|Raku}}
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 2,073 ⟶ 2,966:
 
say "\n391st through 400th magnanimous numbers\n".
join ' ', @M[390..399];</langsyntaxhighlight>
{{out}}
<pre>First 45 magnanimous numbers
Line 2,087 ⟶ 2,980:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">magnanimous</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
Line 2,109 ⟶ 3,002:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"magnanimous numbers[241..250]: %v\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">mag</span><span style="color: #0000FF;">[</span><span style="color: #000000;">241</span><span style="color: #0000FF;">..</span><span style="color: #000000;">250</span><span style="color: #0000FF;">]})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"magnanimous numbers[391..400]: %v\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">mag</span><span style="color: #0000FF;">[</span><span style="color: #000000;">391</span><span style="color: #0000FF;">..</span><span style="color: #000000;">400</span><span style="color: #0000FF;">]})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,119 ⟶ 3,012:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(de **Mod (X Y N)
(let M 1
(loop
Line 2,178 ⟶ 3,071:
(println (head 45 Lst))
(println (head 10 (nth Lst 241)))
(println (head 10 (nth Lst 391))) )</langsyntaxhighlight>
{{out}}
<pre>
Line 2,189 ⟶ 3,082:
This sample can be compiled with the original 8080 PL/M compiler and run under CP/M (or a clone/emulator).
<br>THe original 8080 PL/M only supports 8 and 16 bit quantities, so this only shows magnanimous numbers up to the 250th.
<langsyntaxhighlight lang="plm">100H: /* FIND SOME MAGNANIMOUS NUMBERS - THOSE WHERE INSERTING '+' BETWEEN */
/* ANY TWO OF THE DIGITS AND EVALUATING THE SUM RESULTS IN A PRIME */
BDOS: PROCEDURE( FN, ARG ); /* CP/M BDOS SYSTEM CALL */
Line 2,347 ⟶ 3,240:
END;
CALL PRINT$NL;
EOF</langsyntaxhighlight>
{{out}}
<pre>
Line 2,356 ⟶ 3,249:
MAGANIMOUS NUMBERS 241-250:
17992 19972 20209 20261 20861 22061 22201 22801 22885 24407
</pre>
 
=={{header|Python}}==
<syntaxhighlight lang="python">""" rosettacode.orgwiki/Magnanimous_numbers """
 
from sympy import isprime
 
 
def is_magnanimous(num):
""" True is num is a magnanimous number """
if num < 10:
return True
for i in range(1, len(str(num))):
quo, rem = divmod(num, 10**i)
if not isprime(quo + rem):
return False
return True
 
 
if __name__ == '__main__':
 
K, MCOUNT = 0, 0
print('First 45 magnanimous numbers:')
while MCOUNT < 400:
if is_magnanimous(K):
if MCOUNT < 45:
print(f'{K:4d}', end='\n' if (MCOUNT + 1) % 15 == 0 else '')
elif MCOUNT == 239:
print('\n241st through 250th magnanimous numbers:')
elif 239 < MCOUNT < 250:
print(f'{K:6d}', end='')
elif MCOUNT == 389:
print('\n\n391st through 400th magnanimous numbers:')
elif 389 < MCOUNT < 400:
print(f'{K:7d}', end='')
MCOUNT += 1
K += 1
</syntaxhighlight>{{out}}
<pre>
First 45 magnanimous numbers:
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
 
241st through 250th magnanimous numbers:
17992 19972 20209 20261 20861 22061 22201 22801 22885 24407
 
391st through 400th magnanimous numbers:
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081
</pre>
 
=={{header|Quackery}}==
 
<code>isprime</code> is defined at [[Primality by trial division#Quackery]].
 
<syntaxhighlight lang="Quackery"> [ 10
[ 2dup /mod
over 0 = iff
[ 2drop true ]
done
+ isprime not iff
false done
10 * again ]
unrot 2drop ] is magnanimous ( n --> b )
 
[] 0
[ dup magnanimous
if [ tuck join swap ]
1+
over size 250 =
until ]
drop
say "First 45 magnanimous numbers:" cr
45 split swap echo cr cr
say "Magnanimous numbers 241-250:" cr
-10 split echo cr cr
drop</syntaxhighlight>
 
{{out}}
 
<pre>First 45 magnanimous numbers:
[ 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 ]
 
Magnanimous numbers 241-250:
[ 17992 19972 20209 20261 20861 22061 22201 22801 22885 24407 ]
</pre>
 
Line 2,361 ⟶ 3,339:
{{works with|Rakudo|2020.02}}
 
<syntaxhighlight lang="raku" perl6line>my @magnanimous = lazy flat ^10, (10 .. 1001).map( {
my int $last;
(1 ..^ .chars).map: -> \c { $last = 1 and last unless (.substr(0,c) + .substr(c)).is-prime }
Line 2,384 ⟶ 3,362:
 
put "\n391st through 400th magnanimous numbers";
put @magnanimous[390..399];</langsyntaxhighlight>
{{out}}
<pre>First 45 magnanimous numbers
Line 2,401 ⟶ 3,379:
<br>The '''magna''' function (magnanimous) was quite simple to code and pretty fast, it includes the 1<sup>st</sup> and last digit parity test.
<br>By far, the most CPU time was in the generation of primes.
<langsyntaxhighlight REXXlang="rexx">/*REXX pgm finds/displays magnanimous #s (#s with a inserted + sign to sum to a prime).*/
parse arg bet.1 bet.2 bet.3 highP . /*obtain optional arguments from the CL*/
if bet.1=='' | bet.1=="," then bet.1= 1..45 /* " " " " " " */
Line 2,445 ⟶ 3,423:
end /*k*/ /* [↓] a prime (J) has been found. */
#= #+1; @.#= j; sq.#= j*j; !.j= 1 /*bump #Ps; P──►@.assign P; P^2; P flag*/
end /*j*/; return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 2,463 ⟶ 3,441:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
n = -1
Line 2,536 ⟶ 3,514:
txt = txt + "]"
see txt
</syntaxhighlight>
</lang>
<pre>
Magnanimous numbers 1-45:
Line 2,544 ⟶ 3,522:
[17992,19972,20209,20261,20861,22061,22201,22801,22885,24407]
</pre>
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! RPL code
! Comment
|-
|
DUP2 1 SWAP SUB "+" + ROT ROT
1 + OVER SIZE SUB + STR→ EVAL
≫ ‘'''InsertPlus'''’ STO
"'" SWAP →STR OVER + + DUP SIZE → str len
≪ 2 SF 2 len 2 - FOR j
str j '''InsertPlus'''
IF '''PRIM?''' NOT THEN 2 CF len 'j' STO END
NEXT
2 FS?
≫ ≫ ‘'''MAGN?'''’ STO
≪ → n
≪ { 0 1 2 3 4 5 6 7 8 9 } 10
WHILE OVER SIZE n < REPEAT
IF DUP '''MAGN?''' THEN SWAP OVER + SWAP END
1 +
END DROP
≫ ≫ ‘'''MAGLST'''’ STO
DO 1 + UNTIL DUP '''MAGN?''' END
≫ ‘'''NXMAGN'''’ STO
|
'''InsertPlus''' ''( "'####'" pos -- sum )''
insert a plus sign in the string
evaluate the expression
'''MAGN?''' ''( "'####'" pos -- sum )''
turn ### into "'###'"
for each possibility
add digits
if not a prime, clear flag 2 and exit the loop
'''MAGLST''' ''( n -- { M(1)..M(n) } )''
'''NXMAGN''' ''( x -- next_M(n) )''
|}
 
{{in}}
<pre>
45 MAGLST
17752 NXMAGN NXMAGN NXMAGN NXMAGN NXMAGN NXMAGN NXMAGN NXMAGN NXMAGN NXMAGN
</pre>
 
{{out}}
<pre>
11: { 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 }
10: 17992
9: 19972
8: 20209
7: 20261
6: 20861
5: 22061
4: 22201
3: 22801
2: 22885
1: 24407
</pre>
 
=={{header|Ruby}}==
{{trans|Sidef}}
<langsyntaxhighlight lang="ruby">require "prime"
 
magnanimouses = Enumerator.new do |y|
Line 2,560 ⟶ 3,619:
puts "\n391st through 400th magnanimous numbers:"
puts magnanimouses.first(400).last(10).join(' ')
</syntaxhighlight>
</lang>
{{out}}
<pre>First 45 magnanimous numbers:
Line 2,573 ⟶ 3,632:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">fn is_prime(n: u32) -> bool {
if n < 2 {
return false;
Line 2,626 ⟶ 3,685:
}
println!();
}</langsyntaxhighlight>
 
{{out}}
Line 2,641 ⟶ 3,700:
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081
</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}}==
<langsyntaxhighlight lang="ruby">func is_magnanimous(n) {
1..n.ilog10 -> all {|k|
sum(divmod(n, k.ipow10)).is_prime
Line 2,656 ⟶ 3,778:
 
say "\n391st through 400th magnanimous numbers:"
say is_magnanimous.first(400).last(10).join(' ')</langsyntaxhighlight>
{{out}}
<pre>
Line 2,671 ⟶ 3,793:
=={{header|Swift}}==
{{trans|Rust}}
<langsyntaxhighlight lang="swift">import Foundation
 
func isPrime(_ n: Int) -> Bool {
Line 2,724 ⟶ 3,846:
print(n, terminator: " ")
}
print()</langsyntaxhighlight>
 
{{out}}
Line 2,742 ⟶ 3,864:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<langsyntaxhighlight lang="vbnet">Imports System, System.Console
 
Module Module1
Line 2,775 ⟶ 3,897:
End If : l += 1 : End While
End Sub
End Module</langsyntaxhighlight>
{{out}}
<pre>First 45 magnanimous numbers:
Line 2,792 ⟶ 3,914:
{{libheader|Wren-math}}
{{trans|Go}}
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for Conv, Fmt
import "./math" for Int
var isMagnanimous = Fn.new { |n|
Line 2,830 ⟶ 3,952:
listMags.call(1, 45, 3, 15)
listMags.call(241, 250, 1, 10)
listMags.call(391, 400, 1, 10)</langsyntaxhighlight>
 
{{out}}
Line 2,845 ⟶ 3,967:
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang "XPL0">func IsPrime(N); \Return 'true' if N is prime
int N, I;
[if N <= 2 then return N = 2;
if (N&1) = 0 then \even >2\ return false;
for I:= 3 to sqrt(N) do
[if rem(N/I) = 0 then return false;
I:= I+1;
];
return true;
];
 
func Magnan(N); \Return 'true' if N is a magnanimous number
int N, M, P;
[M:= 0; P:= 1;
loop [N:= N/10;
if N = 0 then return true;
M:= P*rem(0) + M;
P:= P*10;
if not IsPrime(N+M) then return false;
];
];
 
int Cnt, N;
[Cnt:= 0; N:= 0;
Text(0, "First 45 magnanimous numbers:^m^j");
loop [if N < 10 or Magnan(N) then
[Cnt:= Cnt+1;
if Cnt <= 45 then
[Format(4, 0);
RlOut(0, float(N));
if rem(Cnt/15) = 0 then CrLf(0);
];
if Cnt = 241 then
Text(0, "^m^j241st through 250th magnanimous numbers:^m^j");
if Cnt >= 241 and Cnt <= 250 then
[IntOut(0, N); ChOut(0, ^ )];
if Cnt = 391 then
Text(0, "^m^j^j391st through 400th magnanimous numbers:^m^j");
if Cnt >= 391 and Cnt <= 400 then
[IntOut(0, N); ChOut(0, ^ )];
if Cnt >= 400 then quit;
];
N:= N+1;
];
]</syntaxhighlight>
{{out}}
<pre>
First 45 magnanimous numbers:
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
 
241st through 250th magnanimous numbers:
17992 19972 20209 20261 20861 22061 22201 22801 22885 24407
 
391st through 400th magnanimous numbers:
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081 </pre>
9,476

edits