Created
May 23, 2017 13:11
-
-
Save ShinNoNoir/3533f0fb447f5bb0330d5cb32416e9bd to your computer and use it in GitHub Desktop.
Number of necklaces (combinatorics)
This file contains 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
# https://en.wikipedia.org/wiki/Necklace_%28combinatorics%29#Number_of_necklaces | |
from eulerlib import Divisors | |
def N(k, n): | |
divs = Divisors() | |
return sum( divs.phi(d) * k**(float(n)/d) for d in divs.divisors(n) ) / float(n) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternative:
(Based on slide 9 of http://teaching.csse.uwa.edu.au/units/CITS7209/polya.pdf)