MathDB
Large and small number

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

April 8, 2022
number theory

Problem Statement

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