Problem

Source: International Zhautykov Olympiad 2013 - D1 - P2

Tags: modular arithmetic, number theory proposed, number theory



Find all odd positive integers $n>1$ such that there is a permutation $a_1, a_2, a_3, \ldots, a_n$ of the numbers $1, 2,3, \ldots, n$ where $n$ divides one of the numbers $a_k^2 - a_{k+1} - 1$ and $a_k^2 - a_{k+1} + 1$ for each $k$, $1 \leq k \leq n$ (we assume $a_{n+1}=a_1$).