It is $\sum_{n|d} \mu(n)( q^{d/n}-1)\gcd( (q^d-1)/(q^{d/n}-1), m)/\gcd(q^d-1,m)$$$| S \cap S^m | = \sum_{n|d} \mu(n) \frac{ \gcd ( m (q^{d/n}-1), q^{d}-1 )}{ \gcd (q^{d} - 1, m) } $$
BecauseFirst note that $|S \cap S^m | = |S \cap \mathbb F_{q^d}^m |$ because every m’th$m$th power that generates is an m’th$m$th power of a generator, it suffices to do the.
We can count elements of $S$ by an inclusion-exclusion for generatorsargument, subtracting and adding the number of elements in subfields. This gives the setterm $ \mu(n) q^{d/n}$, or $ \mu(n)( q^{d/n}-1)$ if we only count nonzero elements. To count elements of $S$ that are $m$’thth powers, and this iswe use inclusion-exclusion to count the resultnumber of $m$th powers in subfields.
TheTo count the number of nonzero elements of a sub field$\mathbb F_{q^{d/n}}^\times$ that are $m$th powers is the numberin $\mathbb F_{q^d}^\times$, we observe that their $m$th roots are both $ m (q^{d/n}-1)$st roots of elementsunity and $(q^d-1)$st roots of unity, divided by the numberhence are $\gcd ( m (q^{d/n}-1),(q^d-1))$th roots of charactersunity, and each of orderthem has $\gcd(q^d-1, m)$ $m$th roots in $\mathbb F_{q^d}^\times$, timesso the total number of characters of order$m$ trivial on that sub field, explaining the terms in thisthem is $\frac{ \gcd ( m (q^{d/n}-1), q^{d}-1 )}{ \gcd (q^{d} - 1, m) } $.
Inclusion-exclusion gives our formula.