Satisfy the condition: x*p^x ≡ q (mod r)
Problem Brief :
Tanu is a pre final year cs student. She has been given an integer I. And has been asked to compute how many integers x ( 1 <= x <= I) satisfy the below condition:-
x*px ≡ q (mod r)
x*px ≡ q (mod r)
Prerequisite : Basic Mathematics
Approach :
Brute force solution won't work as 'I' is in range of 10^10 . So we need to find out some features of that given equation. We have pr-1≡1(mod r) where r is a prime number by Fermat's Little Theorem, it is obvious that pz mod r falls into a loop and the looping section is r−1. Also, z mod r has a looping section r .We can try to list a chart to show what x*px is with some specific i,j. (In the chart shown below, x is equal to i*(r-1) + j.
Proof for the chart shown above: For a certain i,j we can see that
x*p^x mod r= ((i*(r−1)+j)mod r)* x ^ (i*(r−1)+j) mod (r−1) =( j−i)*x^j mod r.
We can also prove that x*p^x mod r has a looping section r(r−1). So we don't need to list i ≥ r. Therefore, we can enumerate j from 1 to r−1 and calculate q*x^−j . Let's say the result is y, then we have j − i ≡ y (mod r) (You can refer to the chart shown above to see if it is). So for a certain j, the possible i can only be (j−y),r+(j−y),…,r*t + (j−y) . Then we can calculate how many possible answers x in this situation (i.e. decide the minimum and maximum possible t using the given lower bound 1 and upper bound I). Finally we add them together and get the answer.
Comments
Post a Comment