Maths Olympiad Prep

Library / HMMT February /742 of 1302

HMMT February

Algebra Difficulty 5.3 AIME, harder Find the answer

Let f:Z2→Zf: \mathbb{Z}^{2} \rightarrow \mathbb{Z} be a function such that, for all positive integers aa and bb, f(a,b)={b if a>bf(2a,b) if a≤b and f(2a,b)<af(2a,b)−a otherwise f(a, b)= \begin{cases}b & \text { if } a>b \\ f(2 a, b) & \text { if } a \leq b \text { and } f(2 a, b)<a \\ f(2 a, b)-a & \text { otherwise }\end{cases} Compute f(1000,32021)f\left(1000,3^{2021}\right).

A number or a short expression. Fractions can be typed as 3/2, and spacing doesn't matter.

Solution

Note that f(a,b)f(a, b) is the remainder of bb when divided by aa. If a>ba>b then f(a,b)f(a, b) is exactly bb  mod a\bmod a. If instead a≤ba \leq b, our "algorithm" doubles our aa by nn times until we have a×2n>ba \times 2^{n}>b. At this point, we subtract a2n−1‾a^{\overline{2 n-1}} from f(a⋅2n,b)f\left(a \cdot 2^{n}, b\right) and iterate back down until we get a>b−a⋅k>0a>b-a \cdot k>0 and f(a,b)=b−a⋅kf(a, b)=b-a \cdot k for some positive integer kk. This expression is equivalent to b−a⋅k mod ab-a \cdot k \bmod a, or b mod ab \bmod a. Thus, we want to compute 32021 mod 10003^{2021} \bmod 1000. This is equal to 3 mod 83 \bmod 8 and 78 mod 12578 \bmod 125. By CRT, this implies that the answer is 203.

Want a route through all this instead of an archive? The track puts 2,604 problems in a working order, from Junior Challenge level to the IMO shortlist.

Source: Omni-MATH, licensed Apache-2.0. Statement reproduced verbatim; metadata (topic, difficulty) added by this project.