Discrete Logarithm#4318

Discrete Logarithm

8 seconds
256 megabytes
Easy

Given natural numbers , , and , your task is to determine the discrete logarithm of with base modulo . Specifically, you need to find a number (0 \le x < n) such that a^x \equiv b \pmod{n}.

Input

The input consists of a single line containing three integers , , and , separated by spaces (0 \le a, b, n \le 10^{12}), with the condition that n \neq 0.

Output

Output on the first line if the discrete logarithm does not exist. Otherwise, print the value of the discrete logarithm. If there are multiple possible answers, any one of them can be printed.

Examples

Example 1

Loading
Loading