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的和。