reviewed
approved
reviewed
approved
proposed
reviewed
editing
proposed
return sum(mobius(d)*c(n//d) for d in divisors(n, generator=True))//n if n else 1 # Chai Wah Wu, Jul 10 2024
return sum(mobius(d)*c(n//d) for d in divisors(n, generator=True))//n if n else 1 # _Chai Wah Wu_, Jul 10 2024
(Python)
from functools import lru_cache
from itertools import combinations
from math import prod, factorial, gcd
from fractions import Fraction
from sympy.utilities.iterables import partitions
from sympy import mobius, divisors
def A054921(n):
@lru_cache(maxsize=None)
def b(n): return int(sum(Fraction(1<<sum(p[r]*p[s]*gcd(r, s) for r, s in combinations(p.keys(), 2))+sum(((q>>1)+1)*r+(q*r*(r-1)>>1) for q, r in p.items()), prod(q**r*factorial(r) for q, r in p.items())) for p in partitions(n)))
@lru_cache(maxsize=None)
def c(n): return n*b(n)-sum(c(k)*b(n-k) for k in range(1, n))
return sum(mobius(d)*c(n//d) for d in divisors(n, generator=True))//n if n else 1
approved
editing
proposed
approved
editing
proposed
Edward A. Bender and E. Rodney Canfield, <a href="https://doi.org/10.1016/0095-8956(83)90040-0">Enumeration of connected invariant graphs</a>, Journal of Combinatorial Theory, Series B 34.3 (1983): 268-278. See p. 273.
approved
editing
editing
approved