Calculate Euler's Phi Function. >>> euler_phi(100) 40 >>> euler_phi(0) Traceback (most recent call last): ... ValueError: Only positive numbers are accepted >>> euler_phi(-10) Traceback (most recent call last): ... ValueError: Only positive n
(n: int)
| 96 | |
| 97 | |
| 98 | def euler_phi(n: int) -> int: |
| 99 | """Calculate Euler's Phi Function. |
| 100 | >>> euler_phi(100) |
| 101 | 40 |
| 102 | >>> euler_phi(0) |
| 103 | Traceback (most recent call last): |
| 104 | ... |
| 105 | ValueError: Only positive numbers are accepted |
| 106 | >>> euler_phi(-10) |
| 107 | Traceback (most recent call last): |
| 108 | ... |
| 109 | ValueError: Only positive numbers are accepted |
| 110 | """ |
| 111 | if n <= 0: |
| 112 | raise ValueError("Only positive numbers are accepted") |
| 113 | s = n |
| 114 | for x in set(prime_factors(n)): |
| 115 | s *= (x - 1) / x |
| 116 | return int(s) |
| 117 | |
| 118 | |
| 119 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected