Statistics

Problem Statement for "EllysWhatDidYouGet"

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

  1. 9

    Returns: 952

  2. 5

    Returns: 3515

  3. 13

    Returns: 456

  4. 42

    Returns: 149

  5. 1

    Returns: 125000

  6. 2

    Returns: 15486

  7. 3

    Returns: 8941

  8. 4

    Returns: 5582

  9. 6

    Returns: 2339

  10. 7

    Returns: 1683

  11. 8

    Returns: 1246

  12. 10

    Returns: 682

  13. 11

    Returns: 514

  14. 12

    Returns: 482

  15. 14

    Returns: 431

  16. 15

    Returns: 404

  17. 16

    Returns: 377

  18. 17

    Returns: 359

  19. 18

    Returns: 336

  20. 19

    Returns: 324

  21. 20

    Returns: 303

  22. 21

    Returns: 296

  23. 22

    Returns: 286

  24. 23

    Returns: 279

  25. 24

    Returns: 271

  26. 25

    Returns: 256

  27. 26

    Returns: 248

  28. 27

    Returns: 238

  29. 28

    Returns: 231

  30. 29

    Returns: 228

  31. 30

    Returns: 222

  32. 31

    Returns: 220

  33. 32

    Returns: 215

  34. 33

    Returns: 203

  35. 34

    Returns: 194

  36. 35

    Returns: 185

  37. 36

    Returns: 176

  38. 37

    Returns: 175

  39. 38

    Returns: 173

  40. 39

    Returns: 164

  41. 40

    Returns: 151

  42. 41

    Returns: 150

  43. 43

    Returns: 146

  44. 44

    Returns: 142

  45. 45

    Returns: 135

  46. 46

    Returns: 133

  47. 47

    Returns: 131

  48. 48

    Returns: 126

  49. 49

    Returns: 115

  50. 50

    Returns: 101

  51. 51

    Returns: 96

  52. 52

    Returns: 88

  53. 53

    Returns: 88

  54. 54

    Returns: 88

  55. 55

    Returns: 88

  56. 56

    Returns: 88

  57. 57

    Returns: 88

  58. 58

    Returns: 87

  59. 59

    Returns: 84

  60. 60

    Returns: 78

  61. 61

    Returns: 78

  62. 62

    Returns: 78

  63. 63

    Returns: 78

  64. 64

    Returns: 78

  65. 65

    Returns: 78

  66. 66

    Returns: 78

  67. 67

    Returns: 78

  68. 68

    Returns: 78

  69. 69

    Returns: 78

  70. 70

    Returns: 75

  71. 71

    Returns: 75

  72. 72

    Returns: 75

  73. 73

    Returns: 75

  74. 74

    Returns: 75

  75. 75

    Returns: 75

  76. 76

    Returns: 75

  77. 77

    Returns: 75

  78. 78

    Returns: 74

  79. 79

    Returns: 73

  80. 80

    Returns: 69

  81. 81

    Returns: 69

  82. 82

    Returns: 69

  83. 83

    Returns: 69

  84. 84

    Returns: 69

  85. 85

    Returns: 68

  86. 86

    Returns: 67

  87. 87

    Returns: 66

  88. 88

    Returns: 65

  89. 89

    Returns: 63

  90. 90

    Returns: 60

  91. 91

    Returns: 59

  92. 92

    Returns: 58

  93. 93

    Returns: 56

  94. 94

    Returns: 54

  95. 95

    Returns: 52

  96. 96

    Returns: 48

  97. 97

    Returns: 41

  98. 98

    Returns: 33

  99. 99

    Returns: 22

  100. 100

    Returns: 2


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: