Problem Statement
Choose a number between 1 and 9, inclusive. Multiply it by 3. Add 3 to it. Multiply it again by 3. Sum its digits. You got 9, right?
Elly was intrigued by this "magic trick" (that is actually just pure number theory). She now wants to generalize it. In her version you should initially choose a number between 1 and N, inclusive, then you should multiply it by X, add Y, multiply that result by Z, and finally sum the digits of the number you got. If all choices of the initial number lead to the same final result, the girl is satisfied by the triplet (X, Y, Z).
Elly will only consider X, Y, and Z which are positive integers between 1 and 50, inclusive - otherwise the calculations become too difficult for her taste. There is no restriction on whether X, Y, and Z should be equal or not. In the example above X = Y = Z = 3, but (X = 9, Y = 9, Z = 5), (X = 10, Y = 1, Z = 9), or (X = 42, Y = 48, Z = 33) also work for N = 9.
Let's consider the last example in more detail. You may choose any starting value between 1 and 9, inclusive. Suppose you chose the starting value 3. First you multiply it by 42, which gives you 126. Then you add 48, which gives you 174. In the third step you multiply that by 33, getting 5742. Your final answer is the sum of digits of 5742, which is 5+7+4+2 = 18. Starting from the value 1 gives us 1*42 = 42, 42+48 = 90, 90*33 = 2970, and 2+9+7+0 = 18. Similarly, each of the seven other possible starting values produces the final answer 18.
Given the int N, return the number of triplets of positive integers (X, Y, Z) having 1 ⤠X, Y, Z ⤠50, for which all initial numbers between 1 and N yield the same final answer after the sequence of operations described above.
Definition
- Class:
- EllysWhatDidYouGet
- Method:
- getCount
- Parameters:
- int
- Returns:
- int
- Method signature:
- int getCount(int N)
- (be sure your method is public)
Constraints
- N will be an integer between 1 and 100, inclusive.
Examples
9
Returns: 952
5
Returns: 3515
13
Returns: 456
42
Returns: 149