As Gerhard Paseman has commented, more general problems were studied by D.H. Lehmer in his paper [The distribution of totatives][1]. 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)=-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. [1]: 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