Created
December 16, 2021 04:45
-
-
Save igorvanloo/29c3fcfefaf51ad6353ca6cbe44e0797 to your computer and use it in GitHub Desktop.
Möbius function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def Mobius(n): | |
| if n == 1: | |
| return 1 | |
| d = 2 | |
| num_of_primes = 0 | |
| while n > 1: | |
| while n % d == 0: | |
| num_of_primes += 1 | |
| if n % (d*d) == 0: | |
| return 0 | |
| n /= d | |
| d = d + 1 | |
| if d*d > n: | |
| if n > 1: | |
| num_of_primes += 1 | |
| break | |
| return (-1)**num_of_primes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment