Here's what I've managed to get till now(of course, we only have to consider $a$ from $0$ to $n-1$):
If $n \ne 2, n$ isn't prime. Otherwise we'll have $2^n \equiv 1 \pmod n$, a contradiction.
Do prime factorization of $n$. Then the power of each prime factor of $n$ is $1$. Otherwise, we can consider $a=p_1p_2...p_k$, where $p_i$ are the prime factors of $n$. Then we would definitely have $a \mid n$, another contradiction.
Besides, $n$ has $2$ as its factor. Otherwise, we would have $(-1)^{n+1} \equiv 1 \pmod n$.
All above arguments has excluded the case $n=2$, where $n$ satisfies the statement.
That's all i've got. How can I arrange further progress? The Euler $\phi(n) = (p_1-1)(p_2-1)...(p_k-1)$, where $p_i$ are $n$'s prime factors. How can I link it with $n$ itself, and use some results like Fermat's little Theorem?
Update: Found on this page http://www-groups.mcs.st-andrews.ac.uk/~john/Zagier/Problems.html.