Statistics

Problem Statement for "RoundAboutCircle"

Problem Statement

N cells are located around a circle. Cells are numbered 1 through N in the clockwise direction.

Initially, you can place a token into any one of these cells.

In each turn, you look at the number of the cell containing the token and you calculate s, the sum of the digits in that number. You then move the token s cells clockwise.

This process continues until you move the token into a cell that already contained the token before. Your score is the number of cells that were visited by the token at least once during the process (including the initial cell).

Given N, return the maximal possible score you can get.

Definition

Class:
RoundAboutCircle
Method:
maxScore
Parameters:
int
Returns:
int
Method signature:
int maxScore(int N)
(be sure your method is public)

Constraints

  • N will be between 1 and 200000, inclusive.

Examples

  1. 4

    Returns: 3

    The list of possible moves looks like this: 1->2 2->4 3->2 4->4 You can only visit 3 out of 4 cells, and there are two ways to do so: 1->2->4->4 and 3->2->4->4.

  2. 5

    Returns: 4

    If you start on cell 5, the process will terminate after the first move. Otherwise, the token will travel along the loop 1->2->4->3->1 until the entire loop is visited, thus making your score equal to 4.

  3. 17

    Returns: 11

    The longest path of the token is 5->10->11->13->17->8->16->6->12->15->4->8.

  4. 566

    Returns: 176

  5. 1

    Returns: 1

  6. 200000

    Returns: 18707

  7. 99974

    Returns: 14885

  8. 199999

    Returns: 27604

  9. 2

    Returns: 2

  10. 3

    Returns: 2

  11. 6

    Returns: 3

  12. 12

    Returns: 7

  13. 30

    Returns: 15

  14. 42

    Returns: 17

  15. 918

    Returns: 134

  16. 2412

    Returns: 263

  17. 5517

    Returns: 460

  18. 13788

    Returns: 1149

  19. 21177

    Returns: 1583

  20. 29052

    Returns: 2000

  21. 52497

    Returns: 3206

  22. 80100

    Returns: 4548

  23. 94302

    Returns: 5118

  24. 100037

    Returns: 14868

  25. 148518

    Returns: 8052

  26. 176706

    Returns: 9228

  27. 192636

    Returns: 9834

  28. 198162

    Returns: 10026

  29. 199350

    Returns: 10062

  30. 199926

    Returns: 10080

  31. 199971

    Returns: 10086

  32. 199998

    Returns: 10080

  33. 128

    Returns: 67

  34. 218

    Returns: 120

  35. 563

    Returns: 247

  36. 836

    Returns: 281

  37. 1900

    Returns: 494

  38. 3001

    Returns: 759

  39. 4583

    Returns: 1021

  40. 9515

    Returns: 2070

  41. 19606

    Returns: 3802

  42. 32768

    Returns: 5690

  43. 40054

    Returns: 6677

  44. 55651

    Returns: 9363

  45. 65270

    Returns: 10574

  46. 95851

    Returns: 14338

  47. 101027

    Returns: 15157

  48. 125999

    Returns: 18637

  49. 154651

    Returns: 22817

  50. 185225

    Returns: 26549

  51. 196058

    Returns: 27392

  52. 198616

    Returns: 27784

  53. 199912

    Returns: 27940

  54. 199946

    Returns: 27942

  55. 199952

    Returns: 27946

  56. 198765

    Returns: 10044

  57. 192342

    Returns: 17865

  58. 199997

    Returns: 18966

  59. 199943

    Returns: 27909

  60. 199000

    Returns: 27489

  61. 187549

    Returns: 26156

  62. 189999

    Returns: 9720

  63. 123533

    Returns: 18035

  64. 46573

    Returns: 5176

  65. 199995

    Returns: 18417


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: