Skip to content
UPEEC

Modular Inverse

Hard#math#number-theory#fast-exponentiation· solved by 0 · time limit 2.0 s

Find xx with a⋅x≡1(mod109+7)a \cdot x \equiv 1 \pmod{10^9+7}, 0≤x<109+70 \le x < 10^9+7.

Because 109+710^9+7 is prime, Fermat's little theorem gives x=ap−2 mod px = a^{p-2} \bmod p.

Input

A single integer aa (not a multiple of 109+710^9+7).

Output

xx

Constraints

1≤a<109+71 \le a < 10^9+7

Sample 1

Input

2

Output

500000004

Sample 2

Input

3

Output

333333336

Sign in or join free to run and submit your solution.