Let a Lehmer generator xn+1 = R*xn mod M be represented by tuple (M, R).
It is known that its period is maximal if M is a prime and R is a primitive root modulo M.
For a positive integer K, let PF(K) be the set of all prime factors of K.
A primitive root R modulo M can be characterized in two ways:
For given two integers Mmax and D, find all Lehmer generators (M, R) satisfying
The input consists of one line which contains integers Mmax and D separated by space.
It holds 3 ≤ Mmax ≤ 4×1014 and 3 ≤ D ≤ 40.
The output consists of one line containing integers L and Rmax separated by space, where L is the number of feasible Lehmer generators and Rmax is the maximum among their primitive roots R.
10 3Output
3 3The three feasible Lehmer generators are as follows:
20 5Output
7 3The seven feasible Lehmer generators are as follows:
The public data set is intended for easier debugging and approximate program correctness checking. The public data set is stored also in the upload system and each time a student submits a solution it is run on the public dataset and the program output to stdout and stderr is available to him/her.
Link to public data set