Problem

Source: Mongolian MO 2007 Teachers P3

Tags: number theory



Let $p$ be an odd prime number. Let $g$ be a primitive root of unity modulo $p$. Find all the values of $p$ such that the sets $A=\left\{k^2+1:1\le k\le\frac{p-1}2\right\}$ and $B=\left\{g^m:1\le m\le\frac{p-1}2\right\}$ are equal modulo $p$.