Here is another answer that presents an additional twist to the
problem of counting primitive necklaces, namely Power Group
Enumeration (as presented by Harary and Palmer and Fripertinger, in
a different publication), with the group acting on the slots where the
$N$ colors are placed being the cyclic group $C_n$ on $n$ elements and
the group acting on the colors being the symmetric group on $N$
elements $S_N$.
This treats the problem of counting primitive necklaces where colors
may be swapped without the resulting necklaces being considered
different.
As in the other answer we have the relation $$\sum_{d|n} p_d = q_n,$$
but now $q_n$ is computed by Power Group Enumeration. No formula
will be given but we will explain how to compute $q_n$ and present the
relevant Maple code. The desired value for primitive necklaces then
follows by $$p_n = \sum_{d|n} \mu(n/d) q_d.$$
We can compute the number $q_n$ of configurations by Burnside's lemma
which says to average the number of assignments fixed by the elements
of the power group, which has $N!\times |C_n|$ elements and $|C_n|=n$.
But this number is easy to compute. Suppose we have a permutation
$\alpha$ from $C_n$ and a permutation $\beta$ from $S_N.$ If we place
the appropriate number of complete, directed and consecutive copies of
a cycle from $\beta$ on a cycle from $\alpha$ then this assignment is
fixed under the power group action, and this is possible iff the
length of the cycle from $\beta$ divides the length of the cycle from
$\alpha$ and there are as many assignments as the length of $\beta.$
Now the Burnside computation is best done with a CAS, here is the
Maple code.
with(numtheory);
pet_cycleind_symm :=
proc(n)
option remember;
if n=0 then return 1; fi;
expand(1/n*add(a[l]*pet_cycleind_symm(n-l), l=1..n));
end;
pet_flatten_term :=
proc(varp)
local terml, d, cf, v;
terml := [];
cf := varp;
for v in indets(varp) do
d := degree(varp, v);
terml := [op(terml), seq(v, k=1..d)];
cf := cf/v^d;
od;
[cf, terml];
end;
pet_cycleind_cyclic :=
proc(n)
1/n*add(phi(d)*a[d]^(n/d), d in divisors(n));
end;
q :=
proc(n, N)
option remember;
local idx_colors, res, a, b,
flat_a, flat_b, cyc_a, cyc_b, len_a, len_b, p, q;
if n=1 then
idx_colors := [a[1]]
else
idx_colors := pet_cycleind_symm(N);
fi;
res := 0;
for a in pet_cycleind_cyclic(n) do
flat_a := pet_flatten_term(a);
for b in idx_colors do
flat_b := pet_flatten_term(b);
p := 1;
for cyc_a in flat_a[2] do
len_a := op(1, cyc_a);
q := 0;
for cyc_b in flat_b[2] do
len_b := op(1, cyc_b);
if len_a mod len_b = 0 then
q := q + len_b;
fi;
od;
p := p*q;
od;
res := res + p*flat_a[1]*flat_b[1];
od;
od;
res;
end;
p := (n, N) -> add(mobius(n/d)*q(d,N), d in divisors(n));
This gives for two colors ($N=2$) the sequence
$$1, 1, 1, 2, 3, 5, 9, 16, 28, 51, 93, 170,\ldots$$
which is OEIS A000048.
For three colors ($N=3$) we get the sequence
$$1, 1, 2, 4, 8, 22, 52, 140, 366, 992, 2684, 7404,\ldots$$
which is OEIS A002075.
Finally for four colors ($N=4$) we get the sequence
$$1, 1, 2, 5, 10, 35, 102, 360, 1232, 4427, 15934, 58465,\ldots$$
which is OEIS A056300.
Additional linkage. For $N=5$ we find a the sequence
$$1, 1, 2, 5, 11, 38, 122, 496, 2005, 8707, 38364, 173562,\ldots$$
which is OEIS A056301.
For $N=6$ we finde the sequence
$$1, 1, 2, 5, 11, 39, 125, 532, 2301, 11010, 54681, 284023,\ldots$$
which is OEIS A056302.
For $N=7$ we find the sequence
$$1, 1, 2, 5, 11, 39, 126, 536, 2353, 11606, 60498, 336399,\ldots$$
which is not yet in the OEIS.
Addendum Sat Apr 21 2018. The algorithm just presented admits of a
considerable improvement, namely that there is no need to flatten the
permutations because we can compute the contribution from the cycles
of a pair $(\alpha, \beta)$ by multiplying the number of coverings of
a cycle type from $\alpha$ by the number of instances of the cycle
type from $\beta$, raising the result to the power of the number of
instances of the cycle type from $\alpha.$
This yields the following Maple code.
with(numtheory);
pet_cycleind_symm :=
proc(n)
option remember;
if n=0 then return 1; fi;
expand(1/n*add(a[l]*pet_cycleind_symm(n-l), l=1..n));
end;
pet_cycleind_cyclic :=
proc(n)
1/n*add(phi(d)*a[d]^(n/d), d in divisors(n));
end;
q := proc(n, N)
option remember;
local idx_slots, idx_colors, res, term_a, term_b,
v_a, v_b, inst_a, inst_b, len_a, len_b, p, q;
if n = 1 then
idx_slots := [a[1]];
else
idx_slots := pet_cycleind_cyclic(n);
fi;
if N = 1 then
idx_colors := [a[1]];
else
idx_colors := pet_cycleind_symm(N);
fi;
res := 0;
for term_a in idx_slots do
for term_b in idx_colors do
p := 1;
for v_a in indets(term_a) do
len_a := op(1, v_a);
inst_a := degree(term_a, v_a);
q := 0;
for v_b in indets(term_b) do
len_b := op(1, v_b);
inst_b := degree(term_b, v_b);
if len_a mod len_b = 0 then
q := q + len_b*inst_b;
fi;
od;
p := p*q^inst_a;
od;
res := res +
lcoeff(term_a)*lcoeff(term_b)*p;
od;
od;
res;
end;
p := (n, N) -> add(mobius(n/d)*q(d,N), d in divisors(n));