#P3846. Discrete Logarithm Problem

    ID: 17094 Type: Default 1000ms 256MiB

Discrete Logarithm Problem

Discrete Logarithm Problem

Given a prime number \(p\), an integer \(b\), and an integer \(n\), find the smallest non-negative integer \(l\) such that:

$$b^l \equiv n \pmod{p}$$

If no such \(l\) exists, output -1.

inputFormat

The input consists of a single line containing three space-separated integers: \(p\), \(b\), and \(n\), where \(p\) is a prime number.

outputFormat

Output a single integer: the smallest non-negative integer \(l\) satisfying $$b^l \equiv n \pmod{p}$$. If no such integer exists, output -1.

sample

7 3 6
3