Advertisement
add1ctus

ThePermutationGame Text

Mar 9th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. Alice and Bob are playing a game called "The Permutation Game". The game is parameterized with the int N. At the start of the game, Alice chooses a positive integer x, and Bob chooses a permutation of the first N positive integers. Let p be Bob's permutation. Alice will start at 1, and apply the permutation to this value x times. More formally, let f(1) = p[1], and f(m) = p[f(m-1)] for all m >= 2. Alice's final value will be f(x). Alice wants to choose the smallest x such that f(x) = 1 for any permutation Bob can provide. Compute and return the value of such x modulo 1,000,000,007.
  2.  
  3. Notes
  4. - A permutation of the first N positive integers is a sequence of length N that contains each of the integers 1 through N exactly once. The i-th (1-indexed) element of a permutation p is denoted by p[i].
  5.  
  6. Constraints
  7. - N will be between 1 and 100,000 inclusive.
  8.  
  9.  
  10. Examples
  11. 2 - returns 2
  12. 3 - returns 6
  13. 11 - returns 27720
  14. 102 - returns 53580071
  15. 9999 - returns 927702802
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement