RSA

Factor N into its two primes to recover phi(N), then use modular inverse and fast exponentiation to decrypt C and print M.

Medium5Number theoryMathNo attempts yetTime limit2sMemory limit512 MB

Problem

RSA is one of the most widely used public key encryption algorithms. Its basic operation is described below.

Pick two distinct odd primes PP and QQ and compute N=PQN = PQ. Next compute the totient φ(N)=(P1)(Q1)\varphi(N) = (P - 1)(Q - 1) and pick an integer EE with 1<E<φ(N)1 < E < \varphi(N) and gcd(φ(N),E)=1\gcd(\varphi(N), E) = 1. Finally compute DD, the multiplicative inverse of EE modulo φ(N)\varphi(N), that is the integer DD with DE1(modφ(N))DE \equiv 1 \pmod{\varphi(N)}.

This gives the public key, formed by the two integers NN and EE, and the secret key, formed by the two integers NN and DD.

To encrypt a message MM with 0<M<N0 < M < N, compute C=MEmodNC = M^E \bmod N, and CC is the encrypted message. To decrypt it and recover the original message, compute M=CDmodNM = C^D \bmod N. Decryption needs the secret key, and the public key alone is not enough. The expression x1(mody)x \equiv 1 \pmod{y} used above means that the remainder of xx divided by yy is 1.

In this problem you break RSA. Write a program that recovers the original message MM from the public key NN, EE and the ciphertext CC alone.

Input

The single line of input contains three integers NN, EE, CC separated by spaces, where 15N10915 \le N \le 10^9, 1E<N1 \le E < N and 1C<N1 \le C < N.

NN and EE form the RSA public key described above, and CC is a message encrypted with that public key. NN is a product of two distinct odd primes, and gcd(φ(N),E)=1\gcd(\varphi(N), E) = 1 always holds.

Output

Print a single line containing the original message MM, where 1M<N1 \le M < N.