4
I have been pondering the problem for a long time, the most troubling to me is the scope of the data, 2000000000 of 2 billion times how big, how to calculate?
Each time the K-ary of N is required to represent the sum of the figures, then one to take the mold, two requirements division, so large number how to do. The topic test is not a large number of operations, there must be some kind of law, then what is this law?
In the process of thinking, the first consideration is 1. (a*b) mod n = (A * (b mod n)) mod n;
Second, it also takes into account
Each time the K-ary of N is required to represent the sum of the numbers, then the last one and that is 2. N mod (k-1) (this is seen by the law)
But then their own ideas are more chaotic, do not know how to deal with the X-y side of the problem, think for a long time did not think out.
Finally can not help but look at the other people's puzzle,
They did ask for X's Y-side, and used the iterative method to seek, and in the process of seeking direct modulo operation, to avoid data overflow. The gap is here.
The code is as follows
1#include <cstdio>2#include <cstring>3 4typedefLong Longll;5 6 7 intRoot (ll x, ll y, ll K) {8ll mi =1;9 while(y) {Ten if(Y &1) { OneMi = (mi*x)%K; A } -x = (x * x)%K; -y = y >>1; the } - returnmi; - } - + intMain () { - ll X, Y, K; + while(SCANF ("%lld%lld%lld", &x, &y, &k)! =EOF) { All ans = root (x, Y, K1); at if(ans = =0) { -Ans = k-1; - } -printf"%lld\n", ans); - } - return 0; in}
About 2nd
n=a0+a1*k+a2*k^2+......an*k^N N'=a0+a1+a2+......+anN-N'=a1* (k-1) +a2* (k-1) ^2+a3* (k-1) ^3+......+an* (k-1) ^n(N-N')% (k-1) =0(N'- N"')% (k-1) =0 ..... (N (R-1)-N (R))% (K-1)=0Add to (N-N (r))% (K-1)=0N (R)=n% (K-1) therefore (x^y)% (K-1) is what we ask for. When (x^y)% (K-1) =0, note that the result is K-1