Totient function: Difference between revisions
→{{header|BQN}}: Link to primes.bqn version; editing
(→{{header|BQN}}: Link to primes.bqn version; editing) |
|||
Line 393:
GCD function is taken from BQNcrate.
The totient function is similar to APL and J, except it is made as a train. An explicit version of <code>Totient</code> is <code>{+´1=𝕩GCD¨1+↕𝕩}</code>
<lang bqn>GCD ← {𝕨(|𝕊⍟(>⟜0)⊣)𝕩}
Totient ← +´1=⊢GCD¨1+↕</lang>
{{out|Usage}}
<lang bqn> Totient
⟨ 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 16 6 18 8 12 10 22 8 20 ⟩
Line 409 ⟶ 406:
"Prime?" 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0 0
┘</lang>
The [https://github.com/mlochbaum/bqn-libs/blob/master/primes.bqn primes] library from bqn-libs includes a <code>Totient</code> function based on factoring that's much faster for numbers in the hundreds and above.
=={{header|C}}==
|