Mobius function >>> mobius(24) 0 >>> mobius(-1) 1 >>> mobius('asd') Traceback (most recent call last): ... TypeError: '<=' not supported between instances of 'int' and 'str' >>> mobius(10**400) 0 >>> mobius(10**-400) 1 >>> mo
(n: int)
| 10 | |
| 11 | |
| 12 | def mobius(n: int) -> int: |
| 13 | """ |
| 14 | Mobius function |
| 15 | >>> mobius(24) |
| 16 | 0 |
| 17 | >>> mobius(-1) |
| 18 | 1 |
| 19 | >>> mobius('asd') |
| 20 | Traceback (most recent call last): |
| 21 | ... |
| 22 | TypeError: '<=' not supported between instances of 'int' and 'str' |
| 23 | >>> mobius(10**400) |
| 24 | 0 |
| 25 | >>> mobius(10**-400) |
| 26 | 1 |
| 27 | >>> mobius(-1424) |
| 28 | 1 |
| 29 | >>> mobius([1, '2', 2.0]) |
| 30 | Traceback (most recent call last): |
| 31 | ... |
| 32 | TypeError: '<=' not supported between instances of 'int' and 'list' |
| 33 | """ |
| 34 | factors = prime_factors(n) |
| 35 | if is_square_free(factors): |
| 36 | return -1 if len(factors) % 2 else 1 |
| 37 | return 0 |
| 38 | |
| 39 | |
| 40 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected