Discrete Logarithm is a Joke
시간 제한10초메모리 제한256 MB
소수 M과 원시근 g, 이산 로그 함수 f가 주어질 때 고정된 a0에서 시작해 f를 n번 적용한 값을 구한다.
문제
is a prime number. is a primitive root modulo , which means that are all distinct integers from . Let's define a function as the smallest positive integer such that . is a bijection from to .
Let's then define a sequence of numbers as follows:
- (you can copy this number from the sample);
- .
Given , find .
입력
The only line of input contains one integer ().
출력
Print .