2501. Calculation Constraints
Time limit:1 secs, Memory limit:256 MB
Description
_gxx encountered a troublesome equation: S = n
1 + N2 + N3 + ... + NK, known as N, K, for the value of S. Because _GXX maths is poor, I hope you can tell him the answer. But because his math is so bad, you just need to tell him to divide the remainder of s by 9901.InputTwo integers, N and K (n≤1000, k≤109).OutputA number that represents the remainder of s divided by 9901.Sample Input
2 3
Sample Output
14
Problem SourceHuang Jinzhousey--The final sprint of the provincial race
A good mathematical problem, the application of Fermat theorem;
First, by the Fermat theorem, if P is prime, then for number A, there is
Then there are the following two inferences:
1.
2, make Data[i] said
Then there are:
i.e. Data[i] = data[i-1] * n + N; obviously data[1] = n,data[0] = 1; The above 1 indicates that if the value of K is greater than 9901, then n^k = n^ (k-9900), which means that we actually ask for an answer, as long as the preceding 9900 items are calculated You can then put the preceding 9900 items and multiply the number of repetitions (k/9900), plus the number of entries and data[k% 9900]. The code is as follows:#include <stdio.h> #include <algorithm>using namespace Std;int main () { int data[9905], n, K; scanf ("%d%d", &n, &k); Data[0] = 0; Data[1] = n; for (int i = 2; I <= 9900 && i <= K; i++) { Data[i] = (Data[i-1] * n + N)% 9901; } printf ("%d\n", ((data[9900] * (k/9900)) + data[k% 9900])% 9901); return 0;}
Sicily 2501. Calculation calculation