Let f:Z2→Z be a function such that, for all positive integers a and b, f(a,b)=⎩⎨⎧bf(2a,b)f(2a,b)−a if a>b if a≤b and f(2a,b)<a otherwise Compute f(1000,32021).
A number or a short expression. Spacing and $ signs are ignored.
Solution
Note that f(a,b) is the remainder of b when divided by a. If a>b then f(a,b) is exactly bmoda. If instead a≤b, our "algorithm" doubles our a by n times until we have a×2n>b. At this point, we subtract a2n−1 from f(a⋅2n,b) and iterate back down until we get a>b−a⋅k>0 and f(a,b)=b−a⋅k for some positive integer k. This expression is equivalent to b−a⋅kmoda, or bmoda. Thus, we want to compute 32021mod1000. This is equal to 3mod8 and 78mod125. 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.