How to solve the inverse problem of PHP multiplication
This article mainly explains "how to solve the inverse problem of PHP multiplication". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to solve the inverse problem of PHP multiplication.
Recommend lcy
Let S (x) denote the sum of factors of x. The title is: s (2004 ^ X) mod 29
Factor and S are product functions, that is, they satisfy property 1.
Property 1: if gcd (a) b) = 1, then S (a) = S (a) * S (b)
2004 ^ X = 4 ^ X * 3 ^ X * 167 ^ X
S (2004 ^ X) = S (2 ^ (2X)) * S (3 ^ X) * S (167 ^ X)
Property 2: if p is a prime, then S (p ^ X) = 1 ~ p + p ^ 2 +. + p ^ X = (p ^ (X ^ 1)-1) / (p ^ 1)
Therefore: s (2004 ^ X) = (2 ^ (2X+1)-1) * (3 ^ (XIX 1)-1) / 2 * (167 ^ (XIX 1)-1) / 166
167% 29 = 22
S (2004 ^ X) = (2 ^ (2X+1)-1) * (3 ^ (Xuan 1)-1) / 2 * (22 ^ (Xuan 1)-1) / 21
Nature 3: (aqb) / c% M = a% M * b% M * inv (c)
Where inv (c) is the smallest integer that satisfies (c*inv (c))% M é 1, where M = 29
Then inv (1) = 1 in v (2) = 15 in v (22) = 15
There are some good ones:
S (2004 ^ X) = (2 ^ (2X+1)-1) * (3 ^ (Xuan 1)-1) / 2 * (22 ^ (Xuan 1)-1) / 21
= (2 ^ (2X+1)-1) * (3 ^ (Xuan 1)-1) * 15 * (22 ^ (Xuan 1)-1) * 18
Fast power modulus is to find the value of a ^ n mod b in O (logn). The principle of the algorithm is ab mod c = (a mod c) (b mod c) mod c 390MS
# includeusing namespace std;const int pow [] [3] = {{2pr 5je 32}, {3pr 4je 81}, {22pr 2484}}; / 2 ^ 5 > 29,3 ^ 4 > 29,22 ^ 2 > 29, used to find (b ^ I)% 29int PowMod29 (int x index) / / Fast Modulus Power {int ans=1; while (index > = pow [x] [1]) / / when the index is greater than this value, it will exceed 29 {ans= (ans* quotient [x] [2])% 29 / / so model 29. And multiply by the previous value! Index-=pow [x] [1];} while (index--) ans= (ans* accounts [x] [0])% 29 bump / multiply the remaining ones not exceeding 29! Remember that on the mold 29 (because it is possible to exceed 29) return ans;} int main () {int Xpart2 part 2 department 3 part 3 part 167; while (cin > > Xerogram Xerox parts 0) {part2=PowMod29 (0meme 2 million Xerox 1); part3=PowMod29 (1 recorder Xero1); part167=PowMod29 (2 recital Xerox 1); cout