#P5702. Modular Harmonic Sum
Modular Harmonic Sum
Modular Harmonic Sum
Given two integers (n) and (p), along with the smallest primitive root (g) of (p), compute the following sum modulo (p):
[ S = \sum_{i=1}^{n} \frac{1}{i} ]
In other words, you need to calculate (S \bmod p). Note that if you are not familiar with performing modulo operations on fractions, you may refer to this problem for guidance. It is guaranteed that the result exists modulo (p).
inputFormat
The input consists of a single line containing three integers (n), (p), and (g), separated by spaces. Here, (n) is the number of terms in the sum, (p) is a prime modulus, and (g) is the smallest primitive root modulo (p).
outputFormat
Output a single integer which is the value of (S) modulo (p).
sample
5 7 3
1