Solution:
Notice that rn(x) is just x modulo n. Therefore
i∏rn(iai)≡i∏iai(modn)
For primes p, apply Wilson's theorem to see that we must have
i∏iai≡−1(modp)
However,
i∏iai=i∏ii∏ai≡(−1)2≡1(modp)
So the only possibility in that case is p=2.
Now, if n is composite, then let n be the minimal solution. Let n=pq for prime p. Notice that we must have (p−1)q numbers in {a1,2a2,3a3,…,(n−1)an−1} not divisible by p. The q−1 numbers of the form (kp)akp are divisible by p and there are only q−1 multiples of p in {1,2,…,pq−1}. Therefore they must be the only numbers divisible by p, so {akp∣1≤k<q}={kp∣1≤k<q}.
Now, p∤q as otherwise all of (kp)akp are multiples of p2, which is not true.
Let c≡p1(modq). Consider {pap,pa2p,…,pa(q−1)p}={1,2,…,q−1}.
Then,
{pap,p2a2p,…,p(q−1)a(q−1)p}={p2pap,p22pa2p,…,p2(q−1)pa(q−1)p}
≡c{1,2,3,…,q−1}(modq)
As (kp)akp≡k′p (mod pq) for some k′, and kakp≡k′ (mod q)
Since gcd(c,q)=1
c{1,2,3,…,q−1}≡{1,2,3,…,q−1}(modq)
in some order. This is a solution for n=q, which contradicts the minimality of the solution for n=pq. Therefore no such solution n=pq can exist.
Hence, n=2 is the only solution.