Achilles numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|RPL}}: add a few comments)
(→‎{{header|RPL}}: Faster version)
Line 2,779: 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.
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}}
{{works with|HP|49g}}
→ s
FACTORS
'''IF''' DUP SIZE 4 < '''THEN''' DROP 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'''
'''ELSE'''
<span style="color:blue">UNBUNDL</span> → p a <span style="color:grey">@ separates prime factors from their exponents</span>
{ } 2 3 PICK SIZE '''FOR''' j <span style="color:grey">@ keeps exponents only</span>
OVER j GET +
≪ 1 p INV - ΠLIST →NUM * <span style="color:grey">@ get phi(n)</span>
2 '''STEP''' NIP
a ≪ MIN ≫ STREAM 2 ≥
a GCD STREAM 1 ==
→ a
a ≪ MIN ≫ STREAM 2 ≥ a ≪ GCD ≫ STREAM 1 == AND
AND * <span style="color:grey">@ if Achilles, returns phi(n))</span>
'''END'''
'''END'''
Line 2,805: Line 2,799:
≪ { } 1 → n
≪ { } 1 → n
≪ '''WHILE''' DUP SIZE 20 < '''REPEAT'''
≪ '''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'''
'''IF''' 'n' INCR <span style="color:blue">ACH?</span>
'''THEN''' IF n EULER <span style="color:blue">ACH?</span> '''THEN''' n + '''END END'''
'''END'''
'''END'''
≫ ≫ EVAL
≫ ≫ EVAL
Line 2,813: Line 2,808:
1: {500 864 1944 2000 2592 3456 5000 10125 10368 12348 12500 16875 19652 19773 30375 31104 32000 33275 37044 40500}
1: {500 864 1944 2000 2592 3456 5000 10125 10368 12348 12500 16875 19652 19773 30375 31104 32000 33275 37044 40500}
</pre>
</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 14 minutes on the same platform.
First 50 Achilles numbers found in 53 seconds on the ''iHP48'' emulator running on a iPhone Xr; first 20 strong Achilles numbers found in 5 minutes 13 seconds on the same platform.


=={{header|Rust}}==
=={{header|Rust}}==