Achilles numbers: Difference between revisions

m
Python example
(add task to aarch64 assembly raspberry pi)
m (Python example)
Line 2,328:
"30.7s"
</pre>
 
=={{header|Python}}==
<lang python>from math import gcd
from sympy import factorint
def is_Achilles(n):
p = [v for v in factorint(n).values()]
return all(i > 1 for i in p) and gcd(*p) == 1
 
def is_strong_Achilles(n):
return is_Achilles(n) and is_Achilles(totient(n))
def test_strong_Achilles(nachilles, nstrongachilles):
# task 1
print('First', nachilles, 'Achilles numbers:')
n, found = 0, 0
while found < nachilles:
if is_Achilles(n):
found += 1
print(f'{n: 8,}', end='\n' if found % 10 == 0 else '')
n += 1
 
# task 2
print('\nFirst', nstrongachilles, 'strong Achilles numbers:')
n, found = 0, 0
while found < nstrongachilles:
if is_strong_Achilles(n):
found += 1
print(f'{n: 9,}', end='\n' if found % 10 == 0 else '')
n += 1
 
# task 3
print('\nCount of Achilles numbers for various intervals:')
intervals = [[10, 99], [100, 999], [1000, 9999], [10000, 99999], [100000, 999999]]
for interval in intervals:
print(f'{interval}:', sum(is_Achilles(i) for i in range(*interval)))
 
 
test_strong_Achilles(50, 100)
</lang>{{out}}
<pre>
First 50 Achilles numbers:
72 108 200 288 392 432 500 648 675 800
864 968 972 1,125 1,152 1,323 1,352 1,372 1,568 1,800
1,944 2,000 2,312 2,592 2,700 2,888 3,087 3,200 3,267 3,456
3,528 3,872 3,888 4,000 4,232 4,500 4,563 4,608 5,000 5,292
5,324 5,400 5,408 5,488 6,075 6,125 6,272 6,728 6,912 7,200
 
First 100 strong Achilles numbers:
500 864 1,944 2,000 2,592 3,456 5,000 10,125 10,368 12,348
12,500 16,875 19,652 19,773 30,375 31,104 32,000 33,275 37,044 40,500
49,392 50,000 52,488 55,296 61,731 64,827 67,500 69,984 78,608 80,000
81,000 83,349 84,375 93,312 108,000 111,132 124,416 128,000 135,000 148,176
151,875 158,184 162,000 165,888 172,872 177,957 197,568 200,000 202,612 209,952
219,488 221,184 237,276 243,000 246,924 253,125 266,200 270,000 273,375 296,352
320,000 324,000 333,396 364,500 397,953 405,000 432,000 444,528 453,789 455,877
493,848 497,664 500,000 518,616 533,871 540,000 555,579 583,443 605,052 607,500
629,856 632,736 648,000 663,552 665,500 666,792 675,000 691,488 740,772 750,141
790,272 800,000 810,448 820,125 831,875 877,952 949,104 972,000 987,696 1,000,188
 
Count of Achilles numbers for various intervals:
[10, 99]: 1
[100, 999]: 12
[1000, 9999]: 47
[10000, 99999]: 192
[100000, 999999]: 664
</pre>
 
=={{header|Raku}}==
4,102

edits