题意。。。
策略:rt
代码:
#include <stdio.h> #include <string.h> #define temp 10003 int ans(int n, int p){ int res = 1; n %= temp; while(p){ if(p&1) res = (n*res)%temp; n = (n*n)%temp; p /= 2; } return res; } int main(){ int t, n, p; scanf("%d", &t); while(t --){ scanf("%d%d", &n, &p); int sum = 0; //这里的sum初始化必须为0 for(int i = 1; i <= n; i ++){ //i从1开始 sum = (sum+ans(i, p))%temp; } printf("%d\n", sum); } return 0; }
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=420
时间: 2024-10-11 12:00:57