Problem Statement
Let S(n) be the sum of the digits of n. For example, S(484) = 4+8+4 = 16 and S(22) = 2+2 = 4. A positive integer x is called a Rabbit Number if S(x*x) = S(x)*S(x). For example, 22 is a Rabbit Number because S(484) = S(22)*S(22).
Return the number of Rabbit Numbers between low and high, inclusive.
Definition
- Class:
- RabbitNumber
- Method:
- theCount
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int theCount(int low, int high)
- (be sure your method is public)
Constraints
- low will be between 1 and 1,000,000,000, inclusive.
- high will be between low and 1,000,000,000, inclusive.
Examples
22
22
Returns: 1
22 is a Rabbit Number because S(22*22) = S(484) = 16 S(22) * S(22) = 4 * 4 = 16
484
484
Returns: 0
484 is not a Rabbit Number because S(484*484) = S(234256) = 22 S(484) * S(484) = 16 * 16 = 256
1
58
Returns: 12
58
484
Returns: 24
1000000000
1000000000
Returns: 1
1
1000000000
Returns: 7116
3
9
Returns: 1
2
8
Returns: 2
38
54
Returns: 0
7
16
Returns: 4
626
985
Returns: 0
647
678
Returns: 0
4366
8445
Returns: 0
6797
9409
Returns: 0
70762
72091
Returns: 0
31189
97205
Returns: 0
541304
836723
Returns: 0
287737
304686
Returns: 16
224156
7766061
Returns: 850
1794191
2493164
Returns: 254
55997858
84272705
Returns: 0
6229956
70256053
Returns: 1810
528330885
791733587
Returns: 0
88453870
552998244
Returns: 3872
1
1
Returns: 1
200122010
200122010
Returns: 1
1211101
1211101
Returns: 1
101010021
101010021
Returns: 1
21210110
21210110
Returns: 1
10002012
10002012
Returns: 1
220010001
220010001
Returns: 1
2000110
2000110
Returns: 1
1113000
1113000
Returns: 1
101021101
101021101
Returns: 1
111011
111011
Returns: 1
1
999999999
Returns: 7115
10
999999999
Returns: 7112
30010010
1000000000
Returns: 3970
3
1000000000
Returns: 7114
9
999999993
Returns: 7112
2
1000000000
Returns: 7115
2
999999999
Returns: 7114
1
100000000
Returns: 3244
12
10000000
Returns: 1429
1
1000000
Returns: 615
1
199999999
Returns: 5766
4
1000000000
Returns: 7113
155
5345
Returns: 75