Does anyone know a reference to the following results, which I can prove, but I suspect may be known. Let $R(n)$ denote the number of primitive $n$th roots of unity with positive real part, and $L(n)$ the number of primitive $n$th roots of unity with negative real part. Then $\varphi(n)=R(n)+L(n)$ for $n\ne 4$. I am particularly interested in (references to) an explicit formula for the difference function $D(n):=R(n)-L(n)$. I was surprised to
observe (and then prove) that the values of $D(n)$ are zero, or plus or minus a
power of 2. For example,
$$
 D(3)=-2,\quad D(6)=2,\quad D(8)=0,\quad D(21)=4,\quad D(42)=-4.
$$
Three applications of the formula are: $\limsup\_{n\to\infty} D(n)=\infty$, $\lim\_{n\to\infty}D(n)/\varphi(n)=0$, and $\frac{\varphi(n)}{3}\leqslant L(n)\leqslant\frac{2\varphi(n)}{3}$ for $n>6$.



Number of primitive $n$th roots with positive versus negative real parts
As Gerhard Paseman has commented, more general problems were studied by D.H. Lehmer in his paper [The distribution of totatives](http://books.google.com/books?id=k5Y-agKNh68C&pg=PA347&lpg=PA347&dq=lehmer+the+distribution+of+totatives&source=bl&ots=P35LNI-VcC&sig=SvYgiAEnfQDa17xCMRlpPxnzG8I&hl=en&sa=X&ei=zk2mU9fGHoP6oATJ0ICAAw&ved=0CCQQ6AEwAQ#v=onepage&q=lehmer%20the%20distribution%20of%20totatives&f=false). In particular, see section 5 of the paper. From his work it follows that $D(n)$ is a multiplicative function defined on prime powers as follows: $D(p^k)=0$ if $p\equiv 1\pmod 4$ for all $k\ge 1$; $D(p^k)=(-1)^k\times 2$ if $p\equiv 3\pmod 4$ and for all $k\ge 1$; and finally $D(2)=-1$, and $D(2^k)=0$ for all $k\ge 2$. The proofs are based on the simple sieve of Eratosthenes, and clearly this formula establishes that all $D(n)$ are zero or a power of $2$ in magnitude; the other assertions in the problem also follow easily. 


