Totient function: Difference between revisions

Content added Content deleted
(add bQN)
Line 389: Line 389:
1000000 78498
1000000 78498
</pre>
</pre>

=={{header|BQN}}==
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 is <code>{+´1=𝕩GCD¨1+↕𝕩}</code>
<lang bqn>GCD ← {𝕨(|𝕊⍟(>⟜0)⊣)𝕩}
(function block)
Totient ← +´1=⊢GCD¨1+↕
+´1=⊢(function block)¨1+↕
Totient¨1+↕25
⟨ 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 ⟩

"Number"‿"Totient"‿"Prime?"∾˘(⊢∾((⊢≍1⊸=)Totient¨))1+↕25
┌─
╵ "Number" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
"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
"Prime?" 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
┘</lang>


=={{header|C}}==
=={{header|C}}==