Problem

Source: 2022 Taiwan TST Round 2 Independent Study 2-N

Tags: number theory



For any two coprime positive integers $p, q$, define $f(i)$ to be the remainder of $p\cdot i$ divided by $q$ for $i = 1, 2,\ldots,q -1$. The number $i$ is called a large number (resp. small number) when $f(i)$ is the maximum (resp. the minimum) among the numbers $f(1), f(2),\ldots,f(i)$. Note that $1$ is both large and small. Let $a, b$ be two fixed positive integers. Given that there are exactly $a$ large numbers and $b$ small numbers among $1, 2,\ldots , q - 1$, find the least possible number for $q$. Proposed by usjl