nyoj 420

View Code
 1  
 2 /*********************************
 3 /   Problem:
 4 /   Algorithm:
 5 /   Language:   C++
 6 /   Compiler:   MinGW
 7 /   Date:       12/08/08
 8 /
 9 /   Copyright (C) wujianwei
10 /   All rights reserved.
11 ********************************/
12 
13 #include <iostream>
14 #include <cstdio>
15 #include <cstring>
16 #include <cmath>
17 #include <vector>
18 #include <cstring>
19 #include <queue>
20 #include <stack>
21 #include <algorithm>
22 #include <set>
23 
24 using namespace std;
25 
26 #define INF 0x7fffffff
27 #define EPS 1e-12
28 #define MOD 1000000007
29 #define PI 3.141592653579798
30 #define N 100000
31 const int MAX=1<<28;
32 typedef long long LL;
33 //typedef __int64 INT
34 LL sum,m=10003;
35 int poww(int n,int p)
36 {
37     sum=0;
38     for(int i=1; i<=n; i++)
39     {
40         LL k=p,ans=1,t=i;
41         while(k)
42         {
43             if(k&1) ans=ans*t%m;
44              t=(t*t)%m;
45             k=k>>1;
46         }
47         sum=(sum%m+ans%m)%m;
48     }
49     sum%=m;
50 }
51 
52 int main()
53 {
54     int T;
55     scanf("%d",&T);
56     while(T--)
57     {
58         int n,p;
59         scanf("%d%d",&n,&p);
60         poww(n,p);
61         printf("%lld\n",sum);
62     }
63     return 0;
64 }
65         

 

p次方求和

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
 
描述
一个很简单的问题,求1^p+2^p+3^p+……+n^p的和。
 
输入
第一行单独一个数字t表示测试数据组数。接下来会有t行数字,每行包括两个数字n,p,
输入保证0<n<=1000,0<=p<=1000。
输出
输出1^p+2^p+3^p+……+n^p对10003取余的结果,每个结果单独占一行。
样例输入
2
10 1
10 2
样例输出
55
385
来源
原创
上传者
rihkddd
这题目没什么好说的
原文地址:https://www.cnblogs.com/wujianwei/p/2637052.html