Problem Statement
The digits 3 and 9 share an interesting property. If you take any multiple of 3 and sum its digits, you get another multiple of 3. For example, 118*3 = 354 and 3+5+4 = 12, which is a multiple of 3. Similarly, if you take any multiple of 9 and sum its digits, you get another multiple of 9. For example, 75*9 = 675 and 6+7+5 = 18, which is a multiple of 9. Call any digit for which this property holds interesting, except for 0 and 1, for which the property holds trivially.
A digit that is interesting in one base is not necessarily interesting in another base. For example, 3 is interesting in base 10
but uninteresting in base 5. Given an
Definition
- Class:
- InterestingDigits
- Method:
- digits
- Parameters:
- int
- Returns:
- int[]
- Method signature:
- int[] digits(int base)
- (be sure your method is public)
Notes
- When base is greater than 10, digits may have a numeric value greater than 9. Because integers are displayed in base 10 by default, do not be alarmed when such digits appear on your screen as more than one decimal digit. For example, one of the interesting digits in base 16 is 15.
Constraints
- base is between 3 and 30, inclusive.
Examples
10
Returns: { 3, 9 }
All other candidate digits fail for base=10. For example, 2 and 5 both fail on 100, for which 1+0+0=1. Similarly, 4 and 8 both fail on 216, for which 2+1+6=9, and 6 and 7 both fail for 126, for which 1+2+6=9.
3
Returns: { 2 }
9
Returns: { 2, 4, 8 }
26
Returns: { 5, 25 }
30
Returns: { 29 }
4
Returns: { 3 }
5
Returns: { 2, 4 }
6
Returns: { 5 }
7
Returns: { 2, 3, 6 }
8
Returns: { 7 }
11
Returns: { 2, 5, 10 }
12
Returns: { 11 }
13
Returns: { 2, 3, 4, 6, 12 }
14
Returns: { 13 }
15
Returns: { 2, 7, 14 }
16
Returns: { 3, 5, 15 }
17
Returns: { 2, 4, 8, 16 }
18
Returns: { 17 }
19
Returns: { 2, 3, 6, 9, 18 }
20
Returns: { 19 }
21
Returns: { 2, 4, 5, 10, 20 }
22
Returns: { 3, 7, 21 }
23
Returns: { 2, 11, 22 }
24
Returns: { 23 }
25
Returns: { 2, 3, 4, 6, 8, 12, 24 }
27
Returns: { 2, 13, 26 }
28
Returns: { 3, 9, 27 }
29
Returns: { 2, 4, 7, 14, 28 }
27
Returns: { 2, 13, 26 }
3
Returns: { 2 }
30
Returns: { 29 }
23
Returns: { 2, 11, 22 }
26
Returns: { 5, 25 }
13
Returns: { 2, 3, 4, 6, 12 }
16
Returns: { 3, 5, 15 }
9
Returns: { 2, 4, 8 }