
ZOJ Problem Set  1898
Given a prime P, 2 <= P < 2^31, an integer B, 2 <= B < P, and an integer N, 2 <= N < P, compute the discrete logarithm of N, base B, modulo P. That is, find an integer L such that B^L == N (mod P)
Read several lines of input, each containing P,B,N separated by a space, and for each line print the logarithm on a separate line.
If there are several, print the smallest; if there is none, print "no
solution". B^(P1) == 1 (mod P) for any prime P and some other (fairly rare) numbers known as baseB pseudoprimes.
A rarer subset of the baseB pseudoprimes, known as Carmichael numbers, are
pseudoprimes for every base between 2 and P1. A corollary to Fermat's theorem
is that for any m
Source: University of Waterloo Local Contest 2002.01.26 