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 s to open room n, we need gcd(s,n)>1. Since codes are 000-099, the digit sums range from s=0 to s=18.
For room n, the number of accepted codes equals the number of 3-digit codes (with leading zeros) whose digit sum shares a prime factor with n.
First, let's count how many codes have each digit sum s:
- The number of non-negative integer solutions to a+b+c=s where 0≤a,b,c≤9 is the coefficient of xs in (1+x+⋯+x9)3.
- For s≤18, these counts are: s=0:1, s=1:3, s=2:6, s=3:10, s=4:15, s=5:21, s=6:28, s=7:36, s=8:45, s=9:55, s=10:63, s=11:69, s=12:73, s=13:75, s=14:75, s=15:73, s=16:69, s=17:63, s=18:55.
For room n, we sum the counts for all s∈{0,1,…,18} where gcd(s,n)>1.
Note that gcd(0,n)=n>1 for all n≥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⋅32 accepts any s divisible by 2 or 3.
- Multiples of 2: s∈{0,2,4,6,8,10,12,14,16,18} giving 1+6+15+28+45+63+73+75+69+55=430 codes
- Multiples of 3: s∈{0,3,6,9,12,15,18} giving 1+10+28+55+73+73+55=295 codes
- But we double-counted multiples of 6: s∈{0,6,12,18} giving 1+28+73+55=157 codes
- By inclusion-exclusion: 430+295−157=568 codes
Room 60 = 22⋅3⋅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⋅7 gives 522 codes.
Room 90 = 2⋅32⋅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.