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 |
0) | |
| | Returns: 1 | Here there's only one possible permutation. |
|
|
1) | |
| | 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. |
|
|
2) | |
| | Returns: 6 | One of the optimal permutations is 1, 2, 0, 4, 3. |
|
|
3) | |
| |