P power summation time limit: 1000 MS | memory limit: 65535 KB difficulty: 3
-
Description
-
A very simple question: 1 ^ p + 2 ^ p + 3 ^ p + ...... + The sum of n ^ p.
-
Input
-
A separate number t in the first line indicates the number of test data groups. Next, there will be t rows of numbers, each line includes two numbers n, p,
Input 0
-
Output
-
Output 1 ^ p + 2 ^ p + 3 ^ p + ...... + N ^ p returns the remainder of 10003, and each result occupies a single row.
-
Sample Input
-
210 110 2
-
Sample output
-
55385
-
AC code:
-
# Include
# Define N 10003int main () {long T, n, p, I, B, t, a, sum; // long longscanf ("% d ", & T); while (T --) {scanf ("% lld", & n, & p); if (n = 0) // md, potholes, the question n is greater than 0 !!! Printf ("0 \ n"); continue;} sum = 1; for (I = 2; I <= n; I ++) {a = I; B = p; t = 1; while (B) {if (B & 1) t = (t * a) % N; a = (a * a) % N; B = B/2;} sum = (sum + t) % N;} printf ("% d \ n", sum);} return 0 ;}