Achilles numbers: Difference between revisions
Content added Content deleted
m (→{{header|J}}) |
(julia example) |
||
Line 90: | Line 90: | ||
<tt>(#~ predicate) list</tt> selects the elements of <tt>list</tt> where <tt>predicate</tt> is true. |
<tt>(#~ predicate) list</tt> selects the elements of <tt>list</tt> where <tt>predicate</tt> is true. |
||
=={{header|Julia}}== |
|||
<lang>using Primes |
|||
isAchilles(n) = (p = [x[2] for x in factor(n).pe]; all(>(1), p) && gcd(p) == 1) |
|||
isstrongAchilles(n) = isAchilles(n) && isAchilles(totient(n)) |
|||
function teststrongachilles(nachilles = 50, nstrongachilles = 100) |
|||
# task 1 |
|||
println("First $nachilles Achilles numbers:") |
|||
n, found = 0, 0 |
|||
while found < nachilles |
|||
if isAchilles(n) |
|||
found += 1 |
|||
print(rpad(n, 5), found % 10 == 0 ? "\n" : "") |
|||
end |
|||
n += 1 |
|||
end |
|||
# task 2 |
|||
println("\nFirst $nstrongachilles strong Achilles numbers:") |
|||
n, found = 0, 0 |
|||
while found < nstrongachilles |
|||
if isstrongAchilles(n) |
|||
found += 1 |
|||
print(rpad(n, 7), found % 10 == 0 ? "\n" : "") |
|||
end |
|||
n += 1 |
|||
end |
|||
# task 3 |
|||
println("\nCount of Achilles numbers for various intervals:") |
|||
intervals = [10:99, 100:999, 1000:9999, 10000:99999, 100000:999999] |
|||
for interval in intervals |
|||
println(lpad(interval, 15), " ", count(isAchilles, interval)) |
|||
end |
|||
end |
|||
teststrongachilles() |
|||
</lang>{{out}} |
|||
<pre> |
|||
First 50 Achilles numbers: |
|||
72 108 200 288 392 432 500 648 675 800 |
|||
864 968 972 1125 1152 1323 1352 1372 1568 1800 |
|||
1944 2000 2312 2592 2700 2888 3087 3200 3267 3456 |
|||
3528 3872 3888 4000 4232 4500 4563 4608 5000 5292 |
|||
5324 5400 5408 5488 6075 6125 6272 6728 6912 7200 |
|||
First 100 strong Achilles numbers: |
|||
500 864 1944 2000 2592 3456 5000 10125 10368 12348 |
|||
12500 16875 19652 19773 30375 31104 32000 33275 37044 40500 |
|||
49392 50000 52488 55296 61731 64827 67500 69984 78608 80000 |
|||
81000 83349 84375 93312 108000 111132 124416 128000 135000 148176 |
|||
151875 158184 162000 165888 172872 177957 197568 200000 202612 209952 |
|||
219488 221184 237276 243000 246924 253125 266200 270000 273375 296352 |
|||
320000 324000 333396 364500 397953 405000 432000 444528 453789 455877 |
|||
493848 497664 500000 518616 533871 540000 555579 583443 605052 607500 |
|||
629856 632736 648000 663552 665500 666792 675000 691488 740772 750141 |
|||
790272 800000 810448 820125 831875 877952 949104 972000 987696 1000188 |
|||
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}}== |
=={{header|Raku}}== |