Achilles numbers: Difference between revisions

→‎{{header|RPL}}: Faster version
m (→‎{{header|RPL}}: add a few comments)
(→‎{{header|RPL}}: Faster version)
Line 2,779:
Based on Wikipedia definition: n = p<sub>1</sub><sup>a<sub>1</sub></sup>p<sub>2</sub><sup>a<sub>2</sub></sup>…p<sub>k</sub><sup>a<sub>k</sub></sup> is an Achilles number if min(a<sub>1</sub>, a<sub>2</sub>, …, a<sub>k</sub>) ≥ 2 and gcd(a<sub>1</sub>, a<sub>2</sub>, …, a<sub>k</sub>) = 1.
{{works with|HP|49g}}
→ s FACTORS
'''IF''' DUP SIZE 4 < '''THEN''' DROP2DROP 0
≪ { } DUP
1 s SIZE '''FOR''' j
SWAP s j GET + '''NEXT'''
≫ ≫ '<span style="color:blue">UNBUNDL</span>' STO
≪ DUP FACTORS
'''IF''' DUP SIZE 4 < '''THEN''' DROP2 0
'''ELSE'''
<span style="color:blue">UNBUNDL</span> → p a { } 2 3 PICK SIZE '''FOR''' j <span style="color:grey">@ separateskeeps primeexponents factors from their exponentsonly</span>
SWAP s OVER j GET + '''NEXT'''
≪ 1 p INV - ΠLIST →NUM * <span style="color:grey">@ get phi(n)</span>
1 s SIZE2 '''FORSTEP''' jNIP
a ≪ MIN ≫ STREAM 2 ≥
→ a a GCD STREAM 1 ==
a ≪ MIN ≫ STREAM 2 ≥ a ≪ GCD ≫ STREAM 1 == AND
AND * <span style="color:grey">@ if Achilles, returns phi(n))</span>
'''END'''
Line 2,805 ⟶ 2,799:
≪ { } 1 → n
≪ '''WHILE''' DUP SIZE 20 < '''REPEAT'''
'''IF''' 'n' INCR <span style="color:blue">ACH?</span> 4 RND R→I <span style="color:blue">ACH?</span> '''THEN''' n + '''END'''
'''THEN''' IF n EULER <span style="color:blue">ACH?</span> '''THEN''' n + '''END END'''
'''END'''
≫ ≫ EVAL
Line 2,813 ⟶ 2,808:
1: {500 864 1944 2000 2592 3456 5000 10125 10368 12348 12500 16875 19652 19773 30375 31104 32000 33275 37044 40500}
</pre>
First 50 Achilles numbers found in 1 minutes 53 seconds on the ''iHP48'' emulator running on a iPhone Xr; first 20 strong Achilles numbers found in 145 minutes 13 seconds on the same platform.
 
=={{header|Rust}}==
1,150

edits