Wikipedia and Wolfram MathWorld say that the formula for the number of distinct $k$-ary necklaces of length $n$ is:
$$ N_k(n) = \frac{1}{n}\sum_{d|n} {\phi(d)k^{n/d}} $$
What is the intuition behind this formula?
Wikipedia and Wolfram MathWorld say that the formula for the number of distinct $k$-ary necklaces of length $n$ is:
$$ N_k(n) = \frac{1}{n}\sum_{d|n} {\phi(d)k^{n/d}} $$
What is the intuition behind this formula?
Use the commutativity of Dirichlet convolution
$$n N_k(n)= \sum_{d |n} k^{n/d} \phi(d) = \sum_{d |n} k^{n/d} \sum_{l | d} \mu(l) \frac{d}{l} =\sum_{d |n} \frac{n}{d} \sum_{l | d} \mu(l) k^{d/l}$$
where
$k^n$ is the number of $n$-periodic $k$-ary sequences
$f_k(n)=\sum_{l | n} \mu(l) k^{n/l}$ (Möbius inversion) is the number of periodic $k$-ary sequences whose least period is $n$
$\frac{1}{n} f_k(n)$ is the number of $k$-ary sequences whose least period is $n$ and quotiented by the shift equivalence
$\sum_{d | n} \frac{f_k(d)}{d} $ is the number of $k$-ary sequences whose period $| n$ and quotiented by the shift equivalence, ie. the number of necklaces of length $n$.