量化金融 · 第 18 册 · 职业发展

Interviews I: Maths, Probability and Speed

本书暂未推出简体中文版。现有版本:English, Français。

Interviews I: Maths, Probability and Speed · 职业发展

6Number Riddles

Puzzles about whole numbers: the hands of a clock, factorials, remainders, last digits, divisibility, and which amounts can be made from given coins. They reward working modulo a small number and finding a structure rather than a lot of cases. The early questions are warm-ups, and the last ones need real persistence.

Question 6.1 ★ QT, Trader, Analyst • any • junior

What is the angle between the hour and minute hands of a clock at 4:36? Both hands move continuously.

Answer

Answer to Question 6.1.

The angle is 78 degrees.

Work from 12 o’clock. The minute hand moves 6 degrees a minute, so at 36 minutes it is at 216 degrees. The hour hand moves half a degree a minute, so at 4:36 it is at 4×30+36×0.5=1384 \times 30 + 36 \times 0.5 = 138 degrees. The difference is 78 degrees.

Classic wrong answer. Using 120120 degrees for the hour hand, as if it stayed on the 4 for the whole hour. That gives 96.

Follow-up. When do the hands first coincide after 4:00? The minute hand gains 5.55.5 degrees a minute, and it starts 120 degrees behind, so after 120/5.5=21.82120/5.5 = 21.82 minutes, which is about 4:21:49.

Follow-up. How often do they coincide? Eleven times in 12 hours, so every 12/1112/11 of an hour, which is every 65 minutes and about 27 seconds.

Question 6.2 ★ QR, QT, Trader, QD, Dev • any • junior

How many zeros does 250!250! end in, when written out in ordinary decimal digits?

Answer

Answer to Question 6.2.

250!250! ends in 62 zeros.

A trailing zero needs a factor of 10, which is a 2 and a 5. There are many more 2s than 5s among the factors, so the count of 5s decides it. Using Legendre’s formula, multiples of 5 give 250/5=50250/5 = 50, multiples of 25 give a further 10, and multiples of 125 give a further 2. The total is 62.

Classic wrong answer. Stopping at 250/5=50250/5 = 50. A multiple of 25 holds two 5s and a multiple of 125 holds three.

Follow-up. Which factorial ends in exactly 5 zeros? None. 24!24! has 4 zeros, and 25!25! has 6, because the factor 25 brings two 5s at once.

Follow-up. And the last non-zero digit? That is harder, since you must track the unmatched 2s. For 10!10!, the number is 3628800, so the last non-zero digit is 8.

Question 6.3 ★ QR, QT, Trader • any • junior

Without a calculator, what is the last digit of 720267^{2026} when it is written out in decimal?

Answer

Answer to Question 6.3.

The last digit is 9.

Only last digits matter for the last digit of a product. Powers of 7 end in 7, 9, 3, 1 and then repeat, with period 4. Since 2026=4×506+22026 = 4 \times 506 + 2, the power has the same last digit as 72=497^2 = 49.

Classic wrong answer. Using 2026 as if the last digit cycled with period 10. Look at the first few powers, and read the period off directly.

Follow-up. What is the last digit of 7777^{7^7}? You need the exponent modulo 4. Since 7≡−17 \equiv -1 modulo 4 and 777^7 is an odd power, the exponent is ≡3\equiv 3 modulo 4. So the last digit is that of 73=3437^3 = 343, which is 3.

Follow-up. Which digits have a period shorter than 4? The digits 0, 1, 5 and 6 stay fixed, and 4 and 9 have period 2. The digits 2, 3, 7 and 8 have period 4.

Question 6.4 ★ QR, QT, Trader, QD, Dev • any • junior

A corridor has 1000 closed doors, numbered 1 to 1000. For each kk from 1 to 1000, a person walks past and changes the state of every door whose number is a multiple of kk. How many doors are open at the end? How many times is door 72 changed?

Answer

Answer to Question 6.4.

31 doors are open, and door 72 is changed 12 times.

Door nn is changed once for each divisor of nn. Divisors come in pairs, dd and n/dn/d, so the count is even unless the two members of a pair coincide, which happens only for a perfect square. So the open doors are the perfect squares up to 1000: 121^2 up to 312=96131^2 = 961, since 322=102432^2 = 1024.

For door 72, write 72=23×3272 = 2^3 \times 3^2. A divisor chooses a power of 2 from 4 options and a power of 3 from 3, so there are 4×3=124 \times 3 = 12. Being even, door 72 ends closed.

Classic wrong answer. Guessing that half the doors end open, as if each one were a coin toss. The number of changes is entirely decided by the door’s divisors.

Follow-up. Which door below 1000 is changed most often? Door 840, which has 32 divisors, more than any other number below 1000. It ends closed.

Question 6.5 ★ QR, QT, Trader • any • junior

Take any three-digit number and write it twice to make a six-digit number, as in 123123. Why is the result always divisible by 7, 11 and 13?

Answer

Answer to Question 6.5.

Writing a number nn twice gives 1001×n1001 \times n, and 1001=7×11×131001 = 7 \times 11 \times 13.

Writing nn three places to the left and adding nn is the same as 1000n+n1000 n + n. For example, 123123=123×1001123123 = 123 \times 1001. Dividing by 7, then 11, then 13 gives back nn.

Follow-up. How does this give a test for divisibility by 7? Since 1000≡−11000 \equiv -1 modulo 1001, and so modulo 7, split a number into blocks of three digits from the right, and take the alternating sum. For 123456123456 the sum is 456−123=333456 - 123 = 333, which leaves remainder 4 on division by 7, and so does 123456123456. The same test works for 11 and 13.

Follow-up. What does writing a two-digit number twice do? It multiplies by 101, which is prime. So 4747=47×1014747 = 47 \times 101.

Classic wrong answer. Trying examples until you see a pattern. Examples will convince you, but the question asks why, and only the factor of 1001 explains it.

Question 6.6 ★ QR, QT, Trader • any • junior

What is the smallest positive whole number that leaves remainder 1 when divided by 2, remainder 2 when divided by 3, and so on up to remainder 9 when divided by 10?

Answer

Answer to Question 6.6.

The number is 2519.

In each case the remainder is one less than the divisor. So the number plus 1 is divisible by every kk from 2 to 10, and the smallest such number plus 1 is the least common multiple: lcm(2,…,10)=23×32×5×7=2520\mathrm{lcm}(2, \dots, 10) = 2^3 \times 3^2 \times 5 \times 7 = 2520. So the number is 2519.

Classic wrong answer. Answering 10!−1=3 628 79910! - 1 = 3\,628\,799. That does satisfy every condition, but it is not the smallest: the factorial counts repeated factors that the least common multiple does not need.

Follow-up. And up to 20? The least common multiple adds the primes 11, 13, 17 and 19 and one more power of 2: 24×32×5×7×11×13×17×19=232 792 5602^4 \times 3^2 \times 5 \times 7 \times 11 \times 13 \times 17 \times 19 = 232\,792\,560. So the number is 232 792 559232\,792\,559.

Question 6.7 ★★ QR, QT, Trader, QD • any • junior

How many zeros does 20!20! end in when it is written in base 12?

Answer

Answer to Question 6.7.

20!20! ends in 8 zeros in base 12.

A trailing zero in base 12 is a factor of 12, which is 22×32^2 \times 3. Count both primes with Legendre’s formula. For 2: 10+5+2+1=1810 + 5 + 2 + 1 = 18. For 3: 6+2=86 + 2 = 8. Each factor of 12 uses two 2s and one 3, so 2s allow 18/2=918/2 = 9 factors of 12, and 3s allow 8. The smaller count wins, so 8 zeros.

Classic wrong answer. Trusting the base-10 habit of counting only the larger prime. It happens to give 8 here, but you must compare the count of each prime against its exponent in 12, because the limiting prime is not always the larger one. For example, 9!9! has seven 2s and four 3s, so it ends in 3 zeros in base 12, limited by the 2s, and not in 4.

Follow-up. What about base 6 and base 10? Base 6 needs a 2 and a 3 per zero, so min⁡(18,8)=8\min(18, 8) = 8. Base 10 needs a 2 and a 5, so min⁡(18,4)=4\min(18, 4) = 4.

Question 6.8 ★★ QR, QT, Trader • any • junior

The five-digit number 4a27b4a27b, with digits aa and bb, is divisible by 72. Find aa and bb.

Answer

Answer to Question 6.8.

a=3a = 3 and b=2b = 2, so the number is 43272.

Split 72 into its coprime factors, 8 and 9, and use a separate test for each. Divisibility by 8 depends only on the last three digits, 27b27b. Among 270 to 279, only 272 is a multiple of 8, so b=2b = 2. Divisibility by 9 depends on the digit sum, 4+a+2+7+2=15+a4 + a + 2 + 7 + 2 = 15 + a, which must be a multiple of 9, so a=3a = 3. Check: 43272=72×60143272 = 72 \times 601.

Classic wrong answer. Testing multiples of 72, of which there are too many. Use only coprime factors: 72 is 8×98 \times 9, not 6×126 \times 12, because a number can be a multiple of both 6 and 12 without being a multiple of 72.

Follow-up. Is the answer always unique? No. For 7a36b7a36b, bb may be 0 or 8, and these give 72360 and 73368. Check every candidate before you stop.

Question 6.9 ★★ QR, QT, QD • any • junior

What is the remainder when 320263^{2026} is divided by 17? Work it out by hand.

Answer

Answer to Question 6.9.

The remainder is 8.

Use the small powers. Modulo 17, 32=93^2 = 9, 34=81≡13≡−43^4 = 81 \equiv 13 \equiv -4, and 38≡16≡−13^8 \equiv 16 \equiv -1. So 316≡13^{16} \equiv 1, which is what Fermat’s little theorem promises for any number not divisible by 17. Now 2026=16×126+102026 = 16 \times 126 + 10, so

32026≡310=38×32≡−1×9=−9≡8.3^{2026} \equiv 3^{10} = 3^8 \times 3^2 \equiv -1 \times 9 = -9 \equiv 8.

Classic wrong answer. Trying to reduce the exponent modulo 17. The period of powers divides 17−1=1617 - 1 = 16, so you reduce the exponent modulo 16.

Follow-up. Does every base have period 16 here? No. It divides 16. Modulo 17, 3 has period 16, but 24=16≡−12^4 = 16 \equiv -1, so 2 has period 8.

Why it matters. Fast exponentiation and modular arithmetic of this kind are behind hash functions and random-number generators, so a developer may well be asked to code this after working it by hand.

Question 6.10 ★★ QR, QT, Trader • any • junior

A number leaves remainder 1 when divided by each of 2, 3, 4, 5 and 6, and it is divisible by 7. What is the smallest such positive number, and what is the next one?

Answer

Answer to Question 6.10.

The smallest is 301, and the next is 721.

The first five conditions say that n−1n - 1 is a multiple of lcm(2,3,4,5,6)=60\mathrm{lcm}(2, 3, 4, 5, 6) = 60, so n=60k+1n = 60k + 1. Now apply the last condition, modulo 7. Since 60≡460 \equiv 4, you need 4k+1≡04k + 1 \equiv 0, which holds at k=5k = 5, because 4×5+1=214 \times 5 + 1 = 21. So n=301n = 301, which is 7×437 \times 43.

The solutions repeat every lcm(60,7)=420\mathrm{lcm}(60, 7) = 420. That is the Chinese remainder theorem: with coprime moduli, there is exactly one solution in each full period. The next is therefore 721.

Classic wrong answer. Using 2×3×4×5×6=7202 \times 3 \times 4 \times 5 \times 6 = 720 as the period, which gives 721 as the smallest. The common multiple is 60, not 720, and 721 is only the second solution.

Follow-up. Solve remainders 2, 3, 2 on division by 3, 5, 7. Numbers with remainder 2 for both 3 and 7 are 21k+221k + 2. Modulo 5 this is k+2≡3k + 2 \equiv 3, so k=1k = 1, and the answer is 23.

Question 6.11 ★★ QR, QT, Trader, QD • market maker, hedge fund • junior

You have unlimited coins worth 7 and worth 11. What is the largest amount that you cannot pay exactly? How many positive amounts can you not pay?

Answer

Answer to Question 6.11.

The largest amount you cannot pay is 59, and there are 30 amounts you cannot pay.

For two coins aa and bb with no common factor, the largest unreachable amount is ab−a−bab - a - b, which is 77−18=5977 - 18 = 59. The count of unreachable amounts is (a−1)(b−1)/2=6×10/2=30(a - 1)(b - 1)/2 = 6 \times 10 / 2 = 30.

Use remainders modulo 7. Using 7s alone moves you up within a remainder class. So in each class you want to know the smallest amount reachable with 11s: these are 0, 11, 22, 33, 44, 55 and 66, one for each remainder. Once a class has been reached, every later amount in it is reachable. The last amount to be missed is just below the largest of these: 66−7=5966 - 7 = 59. Above that, every class has started.

Follow-up. And with coins worth 6 and 9? Their common factor is 3, so no amount that is not a multiple of 3 is ever reachable, and there is no largest unreachable amount.

Classic wrong answer. Multiplying and answering 77−177 - 1, or thinking that 77 is the first point past which all amounts work. The coins start to cover every class well before 77.

Question 6.12 ★★ QR, QT, Trader, QD, Dev • any • junior

You write out all the whole numbers from 1 to 1000. How many times do you write the digit 1? What is the sum of all the digits of the numbers from 1 to 999?

Answer

Answer to Question 6.12.

You write the digit 1 exactly 301 times, and the digits from 1 to 999 sum to 13 500.

Treat the numbers 0 to 999 as three-digit strings with leading zeros. By symmetry, each digit appears equally often in each place. Each place holds each digit 100 times, so the digit 1 appears 3×100=3003 \times 100 = 300 times. The number 1000 adds one more, for 301.

For the sum, each place contributes 100×(0+1+⋯+9)=4500100 \times (0 + 1 + \dots + 9) = 4500, and three places give 13 50013\,500. The leading zeros and the number 0 add nothing to it, so including them is harmless.

Classic wrong answer. Counting how many numbers contain a 1. That is a different question: among 0 to 999, the numbers without a 1 number 93=7299^3 = 729, so 271 contain a 1. With 1000, this makes 272, while a number such as 111 still contributes three digits to the count of 301.

Follow-up. And the digit 0, from 1 to 1000? Now the leading zeros do matter. The answer is 192: 9 in the numbers 10 to 90, 180 in the three-digit numbers, and 3 in 1000.

Question 6.13 ★★ QR, QT, Trader, QD, Dev • any • junior

What is the smallest set of weights, each a whole number of grams, that lets a balance weigh any object of a whole number of grams from 1 to 40, if a weight may go on either pan? How many weights are needed if they may go on only one pan?

Answer

Answer to Question 6.13.

With either pan allowed, four weights are enough: 1, 3, 9 and 27. With one pan, you need six: 1, 2, 4, 8, 16 and 32.

With both pans, each weight has three states: on the object’s pan, on the other pan, or off. So nn weights give 3n3^n signed sums. These are symmetric about 0, so at most (3n−1)/2(3^n - 1)/2 positive values are reachable. For n=3n = 3 that is 13, which is too few, and for n=4n = 4 it is 40, exactly enough. The powers of 3 achieve it, as every number has one way of being written in balanced ternary, with digits −1-1, 0 and 1. For example, 23=27−3−123 = 27 - 3 - 1, and 40=27+9+3+140 = 27 + 9 + 3 + 1.

With one pan, each weight is on or off, so you are writing the number in binary. Five weights reach only 31, and six reach 63.

Classic wrong answer. Answering 1, 2, 4, 8, 16, 32 for both versions. Binary is optimal for one pan, but it wastes the third state.

Follow-up. Which weights are used for 5 grams? 5=9−3−15 = 9 - 3 - 1: put the 9 on the opposite pan from the object, and the 3 and 1 with the object.

Question 6.14 ★★ QR, QT, QD • any • junior

What are the last two digits of 310003^{1000}? Work it out by hand.

Answer

Answer to Question 6.14.

The last two digits are 01.

Work modulo 100 by repeated squaring. 34=813^4 = 81, so 35=243≡433^5 = 243 \equiv 43. Then 310≡432=1849≡493^{10} \equiv 43^2 = 1849 \equiv 49, and 320≡492=2401≡13^{20} \equiv 49^2 = 2401 \equiv 1. So the powers of 3 repeat with period 20 modulo 100. Since 1000=20×501000 = 20 \times 50, 31000≡13^{1000} \equiv 1.

The general reason is Euler’s theorem: a number coprime to 100 has period dividing φ(100)=40\varphi(100) = 40. Here the true period is 20, which is shorter.

Classic wrong answer. Thinking that the theorem applies to every base. It needs the base to share no factor with 100.

Follow-up. So what are the last two digits of 210002^{1000}? 76. The base 2 shares a factor with 100, so split 100 into 4 and 25. Modulo 4 the power is 0. Modulo 25 the period divides 20, so the power is 1. The only number below 100 that is a multiple of 4 and one more than a multiple of 25 is 76.

Question 6.15 ★★ QR, QT • market maker, hedge fund • junior

Without computing it, what is the highest power of 2 that divides (10050)\binom{100}{50}? What is the highest power of 3? Is (10050)\binom{100}{50} divisible by 7?

Answer

Answer to Question 6.15.

The highest power of 2 is 232^3, the highest power of 3 is 343^4, and 7 does not divide it.

Write (10050)=100!/(50!)2\binom{100}{50} = 100! / (50!)^2, and count each prime with Legendre’s formula. For 2: 100!100! holds 50+25+12+6+3+1=9750 + 25 + 12 + 6 + 3 + 1 = 97, and 50!50! holds 25+12+6+3+1=4725 + 12 + 6 + 3 + 1 = 47, so the answer is 97−94=397 - 94 = 3. For 3: 4848 in 100!100! and 2222 in 50!50!, which leaves 48−44=448 - 44 = 4. For 7: 14+2=1614 + 2 = 16 in 100!100! and 7+1=87 + 1 = 8 in 50!50!, which leaves 0.

Kummer’s theorem says this another way: the power of a prime pp in (a+ba)\binom{a + b}{a} equals the number of carries when adding aa and bb in base pp. In base 7, 50 is 101101, and adding it to itself gives 202202 with no carries, so 7 does not divide it. In base 2, 50=11001050 = 110010 and there are three carries.

Follow-up. Why must the number be even? (2nn)\binom{2n}{n} is always even, as (2nn)=2(2n−1n−1)\binom{2n}{n} = 2 \binom{2n - 1}{n - 1}.

Classic wrong answer. Assuming that every prime up to 100 must divide the number, since 100!100! contains them all. The denominator can cancel every copy, as it does here for 7.

Question 6.16 ★★ QR, QT • any • junior

Show that for every prime pp greater than 3, p2−1p^2 - 1 is divisible by 24.

Answer

Answer to Question 6.16.

Factor: p2−1=(p−1)(p+1)p^2 - 1 = (p - 1)(p + 1), and show that 8 and 3 divide this separately.

Since pp is odd, p−1p - 1 and p+1p + 1 are consecutive even numbers. One of them is a multiple of 4, and the other a multiple of 2, so the product is a multiple of 8. Next, among the three consecutive numbers p−1p - 1, pp and p+1p + 1 one is a multiple of 3. It is not pp, as pp is a prime greater than 3, so 3 divides the product. As 8 and 3 are coprime, 24 divides it. For p=5p = 5, p2−1=24p^2 - 1 = 24, and for p=7p = 7 it is 48, so 24 cannot be replaced by anything larger.

Follow-up. Is primality really needed? No. It uses only that pp is coprime to 6, so 252−1=624=24×2625^2 - 1 = 624 = 24 \times 26 works as well.

Classic wrong answer. Testing 5, 7 and 11 and declaring it proved. Examples show that a claim could be true, and a proof must cover every case.

Follow-up. Is there a similar statement for fourth powers? Yes. For a prime above 5, p4−1p^4 - 1 is a multiple of 240, by the same reasoning with 16, 3 and 5.

Question 6.17 ★★★ QR, QT, Trader, QD • market maker, hedge fund • junior, experienced

Find the four-digit number that becomes its own digits in reverse order when multiplied by 4.

Answer

Answer to Question 6.17.

The number is 2178, since 4×2178=87124 \times 2178 = 8712.

Write it as abcdabcd, with 4×abcd=dcba4 \times abcd = dcba. The product has four digits, so aa is 1 or 2. The product’s last digit is aa and it is also the last digit of 4d4d, which is even, so a=2a = 2. Then d≥8d \geq 8, and 4d4d must end in 2, which rules out d=9d = 9 and leaves d=8d = 8.

Now expand with a=2a = 2 and d=8d = 8:

4(2008+100b+10c)=8002+100c+10b.4(2008 + 100b + 10c) = 8002 + 100c + 10b.

This simplifies to 13b+1=2c13b + 1 = 2c. Since c≤9c \leq 9, bb is at most 1. And b=0b = 0 would make 2c2c odd, so b=1b = 1 and c=7c = 7. So the number is 2178.

Follow-up. What is the matching number for 9? 1089, since 9×1089=98019 \times 1089 = 9801. Putting a 9 in the middle continues the pattern: 4×21978=879124 \times 21978 = 87912, and 9×10989=989019 \times 10989 = 98901.

Classic wrong answer. Searching through thousands of numbers. The first and last digits pin down aa and dd in seconds, and the rest is one line of algebra.

Question 6.18 ★★★ QR, QT, Trader • market maker, hedge fund • junior, experienced

Take every repeating decimal 0.abcabcabc…0.abcabcabc\dots in which aa, bb and cc are three different digits, with zero allowed. What is the sum of all these numbers?

Answer

Answer to Question 6.18.

The sum is 360.

Pair the numbers by symmetry. For 0.abcabc…0.abcabc\dots take its partner with digits 9−a9 - a, 9−b9 - b and 9−c9 - c. The partner’s digits are also different from one another. The two numbers add to 0.999⋯=10.999\dots = 1. No number is its own partner, as a=9−aa = 9 - a has no whole-number solution.

The count of such numbers is 10×9×8=72010 \times 9 \times 8 = 720, which makes 360 pairs, each adding to 1. So the total is 360.

You can check it another way. The value of 0.abcabc…0.abcabc\dots is abc/999abc/999. Each digit appears in each place 72 times, and on average the three-digit string is 499.5499.5, so the total is 720×499.5/999=360720 \times 499.5 / 999 = 360.

Classic wrong answer. Trying to sum in the order of the digits. It can be done, but the pairing removes all the arithmetic. If a sum has a symmetry, look for it first.

Follow-up. What about all 0.abab…0.abab\dots with a≠ba \neq b? There are 90, and the same pairing with 9−a9 - a gives 45 pairs. The sum is 45.

Question 6.19 ★★★ QR, QT, Trader • market maker, hedge fund • junior, experienced

A clock has hour and minute hands of equal length, so you cannot tell them apart, and both move continuously. During one 12-hour cycle, at how many moments are you unable to tell the time from the positions of the hands?

Answer

Answer to Question 6.19.

There are 132 such moments, in 66 pairs.

Measure time tt in units of 12 hours, so 0≤t<10 \le t < 1. The hour hand is at tt of a full turn, and the minute hand at 12t12t, modulo 1. A reading is ambiguous if swapping the hands also gives a valid time ss. That means s=12ts = 12t and t=12st = 12s, modulo 1. Substituting, 144t≡t144 t \equiv t, so 143t143 t is a whole number. There are 143 such values of tt: k/143k/143 for k=0,…,142k = 0, \dots, 142.

Among these, some have the hands together, so that the swap gives the same time. These are the coincidences, with 11t11t a whole number, and there are 11 of them. They are not ambiguous. That leaves 143−11=132143 - 11 = 132. Each pairs with a different time that shows the same picture, so they form 66 pairs.

Classic wrong answer. Answering 143. The 11 moments when the hands overlap do show a unique time, since swapping two identical hands in the same place changes nothing.

Follow-up. Is the moment t=1/143t = 1/143 a real example? Yes. It is 5 minutes and about 2 seconds past 12. The hour hand is at 1/1431/143 of a turn and the minute hand at 12/14312/143. Its swap is t=12/143t = 12/143, which is 1:00:25 or so, where the hour hand is at 12/14312/143 and the minute hand at 144/143≡1/143144/143 \equiv 1/143.

Question 6.20 ★★★ QR, QT, Trader, QD • market maker, hedge fund • junior, experienced

Boxes hold 6, 9 or 20 items, and you must buy whole boxes. What is the largest number of items that you cannot buy exactly? Prove that every larger number can be bought.

Answer

Answer to Question 6.20.

The largest is 43, and every number above it can be bought.

Work modulo 6. Boxes of 6 let you move up within a remainder class, so you only need the smallest amount in each class that the 9s and 20s can reach:

remainder012345smallest amount0492094029\begin{array}{c|cccccc} \text{remainder} & 0 & 1 & 2 & 3 & 4 & 5 \\ \hline \text{smallest amount} & 0 & 49 & 20 & 9 & 40 & 29 \end{array}

Here 49=9+4049 = 9 + 40, 40=20+2040 = 20 + 20 and 29=9+2029 = 9 + 20. Each is the smallest because reaching a remainder of 1, 2, 4 or 5 needs at least one box of 20, and each extra box of 9 only moves you by 3 modulo 6. So the last missing number is in the class of 49, just below it: 49−6=4349 - 6 = 43. Every number from 44 up lies at or above the smallest amount of its class, so 6s finish it.

Classic wrong answer. Using the two-coin formula on 9 and 20 and answering 151. That is right if no boxes of 6 exist. There is no such simple formula for three coin values, so you must do the table.

Follow-up. What does 44 look like, as a check? 44=20+6×444 = 20 + 6 \times 4, and 45=9×545 = 9 \times 5, 46=20+20+646 = 20 + 20 + 6, 47=20+9×347 = 20 + 9 \times 3, 48=6×848 = 6 \times 8, 49=20+20+949 = 20 + 20 + 9. These six in a row, plus 6s, cover all that follow.

Question 6.21 ★★★ QR, QT • market maker, hedge fund • junior, experienced

Which positive whole numbers cannot be written as a sum of two or more consecutive positive whole numbers? Prove it. In how many ways can 2026 be written as such a sum?

Answer

Answer to Question 6.21.

The powers of 2 are exactly the numbers that cannot be written this way. And 2026 can be written in exactly one way: 505+506+507+508505 + 506 + 507 + 508.

Suppose that k≥2k \geq 2 consecutive numbers starting at m≥1m \geq 1 add to nn. Their sum is k(2m+k−1)/2k(2m + k - 1)/2, so

2n=k (2m+k−1).2n = k \, (2m + k - 1).

The two factors have opposite parity, as their difference is 2m−12m - 1, which is odd. The second is larger than kk. If nn is a power of 2 then so is 2n2n, which has no odd factor above 1. So the odd one of the two factors must be 1. But k≥2k \geq 2, and the other factor is larger still, so this is impossible.

Otherwise, nn has an odd factor d>1d > 1. Write 2n2n as a product of the odd part dd and the even part 2n/d2n/d. Call the smaller one kk and the larger 2m+k−12m + k - 1; they have opposite parity, so mm is a whole number, and being the larger makes m≥1m \ge 1. Each odd divisor above 1 gives exactly one way. As 2026=2×10132026 = 2 \times 1013 with 1013 prime, there is one way, with k=4k = 4 and 2m+3=10132m + 3 = 1013.

Follow-up. How many ways for 15? Its odd divisors above 1 are 3, 5 and 15, so three ways: 7+87 + 8, 4+5+64 + 5 + 6 and 1+2+3+4+51 + 2 + 3 + 4 + 5.

Question 6.22 ★★★ QR, QT, QD, Dev • market maker, hedge fund • junior, experienced

100 people stand in a circle, numbered 1 to 100 in order. Going round the circle from person 1, person 1 stays, person 2 leaves, person 3 stays, person 4 leaves, and so on, always skipping one remaining person and removing the next, until one person is left. Which number is left?

Answer

Answer to Question 6.22.

Person 73 is left.

First take the case where the number of people is a power of 2. Each full pass round the circle removes half the people, and ends just before person 1, so the count starts from person 1 again. So person 1 is left when the count is a power of 2.

Now 100=64+36100 = 64 + 36. After 36 people have gone, 64 remain, and the count has reached the person just after the 36th to leave. The 36th to leave is person 72, so the next to stay is person 73, and from there it is the power-of-2 case with person 73 in the role of person 1.

In general, for n=2a+bn = 2^a + b with 0≤b<2a0 \le b < 2^a, the survivor is 2b+12b + 1. In binary this moves the leading digit of nn to the end: 100100 is 11001001100100, and that gives 10010011001001, which is 73.

Classic wrong answer. Answering 1 by the power-of-2 argument, which holds only when the count is a power of 2. Here person 1 survives the first two passes. With 25 left the pass ends on a person who stays, and so person 1 leaves first in the next pass.

Follow-up. What if every third person leaves instead? The neat form is lost. Use the recurrence J(n)=(J(n−1)+3) mod nJ(n) = (J(n - 1) + 3) \bmod n, with people counted from 0. That reaches the number 91 for 100 people, in the numbering of this question.

Question 6.23 ★★★★ QR, QT • market maker, hedge fund • experienced

What is the smallest positive whole number that doubles when its last digit is moved to the front? For example, moving the last digit of 1234 to the front gives 4123. The number may not begin with 0.

Answer

Answer to Question 6.23.

The number is 105 263 157 894 736 842105\,263\,157\,894\,736\,842. It has 18 digits, and doubling it gives 210 526 315 789 473 684210\,526\,315\,789\,473\,684.

Let the number be N=10a+dN = 10a + d, where dd is the last digit and aa has n−1n - 1 digits. Moving dd to the front gives d⋅10n−1+ad \cdot 10^{n-1} + a, and this must equal 2N=20a+2d2N = 20a + 2d. So

19a=d (10n−1−2).19a = d \,(10^{n-1} - 2).

Since d<19d < 19 and 19 is prime, 19 must divide 10n−1−210^{n-1} - 2. So we need the smallest m=n−1m = n - 1 with 10m≡210^m \equiv 2 modulo 19. Working through the powers of 10 gives m=17m = 17.

Then a=d(1017−2)/19a = d(10^{17} - 2)/19. With d=1d = 1 this has only 16 digits, which would force a leading zero in NN. The smallest valid value is d=2d = 2, which gives a=10 526 315 789 473 684a = 10\,526\,315\,789\,473\,684 with all 17 digits.

You can also build it by hand from the right: start with last digit 2, and double repeatedly, writing each digit of the product to the left of the last. You stop after writing a 1 with no carry out, because its double is 2, the digit you started from. That is the quickest way to the digits by hand.

Follow-up. Why are these digits familiar? They are the repeating block of 2/192/19 written as a decimal.

Follow-up. And for tripling? The same steps with 29a=d(10n−1−3)29a = d(10^{n-1} - 3) give a 28-digit answer, 1 034 482 758 620 689 655 172 413 7931\,034\,482\,758\,620\,689\,655\,172\,413\,793.

Question 6.24 ★★★★ QR, QT • market maker, hedge fund • experienced

Let AA be the sum of the decimal digits of 444444444444^{4444}. Let BB be the sum of the digits of AA, and let CC be the sum of the digits of BB. What is CC? Find it by hand.

Answer

Answer to Question 6.24.

C=7C = 7.

The trick is not to compute the number. Two facts settle it: the sum of digits keeps the remainder modulo 9, and the digit sums shrink very fast.

First, the remainder. 4444≡16≡74444 \equiv 16 \equiv 7 modulo 9. Powers of 7 modulo 9 go 7, 4, 1 and repeat, with period 3. Since 4444≡14444 \equiv 1 modulo 3, 44444444≡74444^{4444} \equiv 7 modulo 9, and so C≡7C \equiv 7 as well.

Next, the size. The number is below 10 0004444=1017 77610\,000^{4444} = 10^{17\,776}, so it has at most 17 77617\,776 digits, and A≤9×17 776=159 984A \le 9 \times 17\,776 = 159\,984. A number up to that size has six digits at most, and the first of six is 1, so B≤1+5×9=46B \le 1 + 5 \times 9 = 46. Up to 46, the largest digit sum belongs to 39, so C≤12C \le 12. The only number up to 12 with remainder 7 on division by 9 is 7.

Classic wrong answer. Assuming that the digit sum of a large power is about 4.54.5 a digit and estimating from there. That gives AA and BB only roughly, and the remainder is what fixes the answer.

Follow-up. What are the actual values? Direct computation gives A=72 601A = 72\,601, B=16B = 16 and C=7C = 7. Note that AA is well below its bound, near 4.54.5 a digit.

Question 6.25 ★★★★ QR, QT, Trader • market maker, hedge fund • experienced

Five sailors gather a pile of coconuts. During the night each wakes once, in turn. Each divides the pile into five equal shares with one coconut over, gives that coconut to a monkey, hides one share and pushes the other four back into a pile. In the morning the remaining coconuts divide exactly into five equal shares. What is the smallest possible number of coconuts in the original pile?

Answer

Answer to Question 6.25.

The smallest possible number is 3121.

Each sailor takes a pile xx and leaves 45(x−1)\tfrac45(x - 1). The neat step is to add four ghost coconuts: since 45(x−1)+4=45(x+4)\tfrac45(x - 1) + 4 = \tfrac45(x + 4), the quantity x+4x + 4 simply gets multiplied by 45\tfrac45 at each step. So after five sailors,

final+4=(45)5(N+4).\text{final} + 4 = \left(\tfrac45\right)^5 (N + 4).

For this to be whole, 555^5 must divide N+4N + 4, so N+4=3125 kN + 4 = 3125\,k and the final pile is 1024 k−41024\,k - 4. The final pile must also divide by 5, and 1024 k−4≡4k−41024\,k - 4 \equiv 4k - 4 modulo 5, so k≡1k \equiv 1. The smallest is k=1k = 1, which gives N=3121N = 3121.

Check: the piles go 31213121, 24962496, 19961996, 15961596, 12761276, 10201020, and 1020=5×2041020 = 5 \times 204.

The value −4-4 is the fixed point of the step, since 45(−4−1)=−4\tfrac45(-4 - 1) = -4. If negative coconuts were allowed, a pile of −4-4 would stay −4-4 forever, and this is what suggests the ghost coconuts.

Classic wrong answer. Working backwards from a guess at the final pile and trying each in turn. It will reach 3121, but you must try many values, and you cannot tell whether you have the smallest.

Follow-up. And if one more coconut goes to the monkey in the morning? The final pile must be one more than a multiple of 5: 1024 k−4≡11024\,k - 4 \equiv 1 needs k≡0k \equiv 0 modulo 5, so k=5k = 5, which gives N=56−4=15 621N = 5^6 - 4 = 15\,621.