Magnanimous numbers: Difference between revisions

(Added BASIC256)
Line 2,725:
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>
 
4,102

edits