Maths Olympiad Prep

Library / /632 of 860

Algebra Difficulty 5.3 AIME, harder Find the answer

Let f:Z2Zf: \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 ab 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. Spacing and $ signs are ignored.

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 moda\bmod a. If instead aba \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 a2n1a^{\overline{2 n-1}} from f(a2n,b)f\left(a \cdot 2^{n}, b\right) and iterate back down until we get a>bak>0a>b-a \cdot k>0 and f(a,b)=bakf(a, b)=b-a \cdot k for some positive integer kk. This expression is equivalent to bakmodab-a \cdot k \bmod a, or bmodab \bmod a. Thus, we want to compute 32021mod10003^{2021} \bmod 1000. This is equal to 3mod83 \bmod 8 and 78mod12578 \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,000 problems in a working order, from AMC 10 level to the IMO shortlist.

Source: Omni-MATH, licensed Apache-2.0. Statement and solution reproduced as published; topic and difficulty added by this site.