Identity Function

N이 주어질 때, 모든 a < N에 대해 a^N mod N을 반복 적용하면 a로 돌아오는 최소 k를 구하고, 없으면 -1을 출력한다.

어려움9정수론수학아직 제출이 없습니다시간 제한5초메모리 제한512 MB

문제

You are given an integer NN, which is greater than 11.

Consider the following functions:

  • f(a)=aNmodNf(a) = a^N \bmod N
  • F_1(a)=f(a)F\_1(a) = f(a)
  • F\_{k+1}(a) = F\_k(f(a))\~\~(k = 1,2,3,\ldots)

Note that we use mod\mathrm{mod} to represent the integer modulo operation. For a non-negative integer xx and a positive integer yy, xmodyx \bmod y is the remainder of xx divided by yy.

Output the minimum positive integer kk such that F_k(a)=aF\_k(a) = a for all positive integers aa less than NN. If no such kk exists, output 1-1.

입력

The input consists of a single line that contains an integer NN (2N1092 \le N \le 10^9), whose meaning is described in the problem statement.

출력

Output the minimum positive integer kk such that F_k(a)=aF\_k(a) = a for all positive integers aa less than NN, or 1-1 if no such kk exists.