This page is still under construction.

Parts of this page are still being built. What you see may change.

Identity Function

Time limit5sMemory limit512 MB

Summary
Given N, find the smallest positive k with every iterate F_k(a)=a for 1<=a<N under f(a)=a^N mod N, or output -1.
Level

Hard8 of 10

Topics
Math, Number theory, Recursion
Solved
No attempts yet

Problem

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

Consider the following functions:

  • f(a)=aN mod Nf(a) = a^N \bmod N
  • F1(a)=f(a)F_1(a) = f(a)
  • Fk+1(a)=Fk(f(a))F_{k+1}(a) = F_k(f(a)) (k=1,2,3,…k = 1,2,3,\ldots)

Here mod\mathrm{mod} denotes the integer modulo operation. For a non-negative integer xx and a positive integer yy, x mod yx \bmod y is the remainder of xx divided by yy.

Output the minimum positive integer kk such that Fk(a)=aF_k(a) = a for all positive integers aa less than NN. If no such kk exists, output −1-1.

Input

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

Output

Output the minimum positive integer kk such that Fk(a)=aF_k(a) = a for all positive integers aa less than NN, or −1-1 if no such kk exists.

Examples3

  1. Example 1

    Input
    3
    
    Expected output
    1
    
  2. Example 2

    Input
    4
    
    Expected output
    -1
    
  3. Example 3

    Input
    15
    
    Expected output
    2