Daily

Random

Practice set

Baltic Way 2025 · Problem 20

Number Theory

Determine all positive integers nn such that there exists a permutation a1,…,ana_1,\ldots,a_n of 1,…,n1,\ldots,n, where the numbers a1,2a2,…,nana_1,2a_2,\ldots,na_n are all pairwise distinct modulo nn.

Change pool

When you’re ready

Review material becomes available with the next Daily.

Review

Topics

Modular arithmetic

Solutions

Solution

The answer is n=1n=1 and n=2n=2.

First note that

gcd⁡(x,n)=gcd⁡(x+kn,n)\gcd(x,n)=\gcd(x+kn,n)

for all integers x,kx,k and positive nn. Since (a1,…,an)(a_1,\ldots,a_n) is a permutation of 1,…,n1,\ldots,n and (a1,2a2,…,nan)(a_1,2a_2,\ldots,na_n) is a complete set of residues modulo nn, the three sequences

(gcd⁡(1,n),…,gcd⁡(n,n)),(\gcd(1,n),\ldots,\gcd(n,n)), (gcd⁡(a1,n),…,gcd⁡(an,n)),(\gcd(a_1,n),\ldots,\gcd(a_n,n)),

and

(gcd⁡(a1,n),gcd⁡(2a2,n),…,gcd⁡(nan,n))(\gcd(a_1,n),\gcd(2a_2,n),\ldots,\gcd(na_n,n))

are permutations of one another.

Also,

gcd⁡(k,n)≤gcd⁡(kak,n)andgcd⁡(ak,n)≤gcd⁡(kak,n).\gcd(k,n)\le\gcd(ka_k,n) \qquad\text{and}\qquad \gcd(a_k,n)\le\gcd(ka_k,n).

Because the corresponding sequences have the same sum, equality must hold termwise:

gcd⁡(k,n)=gcd⁡(kak,n)=gcd⁡(ak,n)\gcd(k,n)=\gcd(ka_k,n)=\gcd(a_k,n)

for every 1≤k≤n1\le k\le n.

For each divisor xx of nn, let

Sx={k:1≤k≤n, gcd⁡(k,n)=x}.S_x=\{k:1\le k\le n,\ \gcd(k,n)=x\}.

The maps k↦akk\mapsto a_k and k↦kak(modn)k\mapsto ka_k\pmod n are bijections, and the equality above shows that they map each SxS_x bijectively to itself.

Suppose first that p2∣np^2\mid n for some prime pp. Then

gcd⁡(ap,n)=pandgcd⁡(pap,n)=p.\gcd(a_p,n)=p \qquad\text{and}\qquad \gcd(pa_p,n)=p.

The first equality implies p∣app\mid a_p. Hence p2∣papp^2\mid pa_p, and because p2∣np^2\mid n we get p2∣gcd⁡(pap,n)p^2\mid\gcd(pa_p,n), a contradiction. Thus nn is squarefree.

Now suppose an odd prime pp divides nn, and put q=n/pq=n/p. Since nn is squarefree,

Sq={q,2q,…,(p−1)q}.S_q=\{q,2q,\ldots,(p-1)q\}.

Let

s=q⋅2q⋯(p−1)q.s=q\cdot2q\cdots(p-1)q.

Because k↦akk\mapsto a_k permutes SqS_q,

s=aqa2q⋯a(p−1)q.s=a_q a_{2q}\cdots a_{(p-1)q}.

Because k↦kak(modn)k\mapsto ka_k\pmod n also permutes SqS_q,

s≡(qaq)(2qa2q)⋯((p−1)qa(p−1)q)(modn).s\equiv (qa_q)(2qa_{2q})\cdots((p-1)q a_{(p-1)q})\pmod n.

Reducing modulo pp and using the preceding identity gives

s≡s2(modp).s\equiv s^2\pmod p.

Since p∤qp\nmid q, also p∤sp\nmid s, so we may divide by ss modulo pp:

1≡s≡(p−1)!qp−1(modp).1\equiv s\equiv (p-1)!q^{p-1}\pmod p.

By Wilson's theorem and Fermat's little theorem,

1≡(−1)⋅1≡−1(modp),1\equiv(-1)\cdot1\equiv-1\pmod p,

so p∣2p\mid2, contradicting that pp is odd. Therefore the only prime that may divide nn is 22.

Since nn is squarefree, this leaves only n=1n=1 and n=2n=2. The case n=1n=1 is trivial. For n=2n=2, take (a1,a2)=(1,2)(a_1,a_2)=(1,2); then a1≡1(mod2)a_1\equiv1\pmod2 and 2a2=4≡0(mod2)2a_2=4\equiv0\pmod2, so the required residues are distinct.

Contest context

Results from Baltic Way 2025

11 teams

Mean score
3.9 / 5
Scores of 4 or 5
8 / 11
Estonia
5 / 5

Score distribution

00
12
21
30
41
57
All team scores
TeamScore
Germany5 / 5
Estonia5 / 5
Poland5 / 5
Lithuania5 / 5
Norway5 / 5
Latvia1 / 5
Finland4 / 5
Denmark5 / 5
Sweden5 / 5
Ukraine2 / 5
Iceland1 / 5