Phi is the Euler totient function. This function computes the number of numbers less then n that are coprime with n.
(n int64)
| 3 | // Phi is the Euler totient function. |
| 4 | // This function computes the number of numbers less then n that are coprime with n. |
| 5 | func Phi(n int64) int64 { |
| 6 | result := n |
| 7 | for i := int64(2); i*i <= n; i += 1 { |
| 8 | if n%i == 0 { |
| 9 | for { |
| 10 | if n%i != 0 { |
| 11 | break |
| 12 | } |
| 13 | n /= i |
| 14 | } |
| 15 | result -= result / i |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | if n > 1 { |
| 20 | result -= result / n |
| 21 | } |
| 22 | return result |
| 23 | } |
no outgoing calls