Statistics

Problem Statement for "MagicStones"

Problem Statement

You and your friend have N different stones placed in a row. A permutation of N stones can be described by N numbers: x0, x1, ... , xN-1, where all xi are distinct and each xi is between 0 and N-1, inclusive. When a permutation is applied to the stones, stone placed at position i is moved to position xi. You tell a permutation of length N to your friend and every day he applies it to the stones until they are situated in the same order as in the beginning. You want your friend to spend as many days as possible, so you select the permutation which maximizes the number of days. Given N, return the number of days your friend will have to move the stones.

Definition

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

Constraints

  • N will be between 1 and 50, inclusive.

Examples

  1. 1

    Returns: 1

    Here there's only one possible permutation.

  2. 2

    Returns: 2

    There're two possible permutations. If you select the permutation that swaps two stones, then your friend will have to spend two days.

  3. 3

    Returns: 3

  4. 4

    Returns: 4

  5. 5

    Returns: 6

    One of the optimal permutations is 1, 2, 0, 4, 3.

  6. 6

    Returns: 6

  7. 7

    Returns: 12

  8. 8

    Returns: 15

  9. 9

    Returns: 20

  10. 10

    Returns: 30

  11. 11

    Returns: 30

  12. 12

    Returns: 60

  13. 13

    Returns: 60

  14. 14

    Returns: 84

  15. 15

    Returns: 105

  16. 16

    Returns: 140

  17. 17

    Returns: 210

  18. 18

    Returns: 210

  19. 19

    Returns: 420

  20. 20

    Returns: 420

  21. 21

    Returns: 420

  22. 22

    Returns: 420

  23. 23

    Returns: 840

  24. 24

    Returns: 840

  25. 25

    Returns: 1260

  26. 26

    Returns: 1260

  27. 27

    Returns: 1540

  28. 28

    Returns: 2310

  29. 29

    Returns: 2520

  30. 30

    Returns: 4620

  31. 31

    Returns: 4620

  32. 32

    Returns: 5460

  33. 33

    Returns: 5460

  34. 34

    Returns: 9240

  35. 35

    Returns: 9240

  36. 36

    Returns: 13860

  37. 37

    Returns: 13860

  38. 38

    Returns: 16380

  39. 39

    Returns: 16380

  40. 40

    Returns: 27720

  41. 41

    Returns: 30030

  42. 42

    Returns: 32760

  43. 43

    Returns: 60060

  44. 44

    Returns: 60060

  45. 45

    Returns: 60060

  46. 46

    Returns: 60060

  47. 47

    Returns: 120120

  48. 48

    Returns: 120120

  49. 49

    Returns: 180180

  50. 50

    Returns: 180180


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: