2026-08-19

Problem — 2026-08-19

Medium

MediumNumber theory

A museum curator is designing a security system where each of the 100 rooms is assigned a unique 3-digit code from 000 to 099. The system has a quirk: when a guard enters a code, the door opens if the code's digits sum to a number that shares at least one prime factor with the room number. For example, room 42 accepts code 017 because 0+1+7=8, and gcd(8,42)=2>1. The curator wants to know: which room accepts the most different codes?

Give the room number (0-99)

Show solution
For a code with digit sum ss to open room nn, we need gcd⁡(s,n)>1\gcd(s,n) > 1. Since codes are 000-099, the digit sums range from s=0s=0 to s=18s=18. For room nn, the number of accepted codes equals the number of 3-digit codes (with leading zeros) whose digit sum shares a prime factor with nn. First, let's count how many codes have each digit sum ss: - The number of non-negative integer solutions to a+b+c=sa+b+c=s where 0≤a,b,c≤90 \le a,b,c \le 9 is the coefficient of xsx^s in (1+x+⋯+x9)3(1+x+\cdots+x^9)^3. - For s≤18s \le 18, these counts are: s=0:1s=0:1, s=1:3s=1:3, s=2:6s=2:6, s=3:10s=3:10, s=4:15s=4:15, s=5:21s=5:21, s=6:28s=6:28, s=7:36s=7:36, s=8:45s=8:45, s=9:55s=9:55, s=10:63s=10:63, s=11:69s=11:69, s=12:73s=12:73, s=13:75s=13:75, s=14:75s=14:75, s=15:73s=15:73, s=16:69s=16:69, s=17:63s=17:63, s=18:55s=18:55. For room nn, we sum the counts for all s∈{0,1,…,18}s \in \{0,1,\ldots,18\} where gcd⁡(s,n)>1\gcd(s,n)>1. Note that gcd⁡(0,n)=n>1\gcd(0,n)=n>1 for all n≥2n \ge 2, so the code 000 works for rooms 2-99. The key insight: highly composite numbers with many small prime factors will accept more sums. Consider: - Room 72 = 23⋅322^3 \cdot 3^2 accepts any ss divisible by 2 or 3. - Multiples of 2: s∈{0,2,4,6,8,10,12,14,16,18}s \in \{0,2,4,6,8,10,12,14,16,18\} giving 1+6+15+28+45+63+73+75+69+55=4301+6+15+28+45+63+73+75+69+55=430 codes - Multiples of 3: s∈{0,3,6,9,12,15,18}s \in \{0,3,6,9,12,15,18\} giving 1+10+28+55+73+73+55=2951+10+28+55+73+73+55=295 codes - But we double-counted multiples of 6: s∈{0,6,12,18}s \in \{0,6,12,18\} giving 1+28+73+55=1571+28+73+55=157 codes - By inclusion-exclusion: 430+295−157=568430+295-157=568 codes Room 60 = 22⋅3⋅52^2 \cdot 3 \cdot 5 also accepts multiples of 2, 3, or 5: - Using inclusion-exclusion with multiples of 2, 3, 5, 6, 10, 15, 30 gives 565 codes. Room 84 = 22⋅3⋅72^2 \cdot 3 \cdot 7 gives 522 codes. Room 90 = 2⋅32⋅52 \cdot 3^2 \cdot 5 gives 565 codes. After checking all highly composite numbers up to 99, room 72 accepts the most codes with 568 total. The answer is 72\boxed{72}.