标签:des style blog http java color
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 3754 Accepted Submission(s):
1216
1 #include<iostream> 2 #include<stdio.h> 3 #include<cstring> 4 #include<cstdlib> 5 using namespace std; 6 typedef __int64 LL; 7 8 void solve(int sum,int p) 9 { 10 int i; 11 LL ans = 1 ,cur = 1 % p ; 12 for(i=1;i<=sum;i++) 13 { 14 ans = (ans * i)%p; 15 cur = (cur + ans)%p; 16 if(ans == 0)break; 17 } 18 printf("%I64d\n",cur); 19 } 20 int main() 21 { 22 int T; 23 int i,p; 24 char a[1002]; 25 scanf("%d",&T); 26 while(T--) 27 { 28 scanf("%s%d",a,&p); 29 if(p==1) 30 { 31 printf("0\n"); 32 continue; 33 } 34 int sum = 0; 35 for(i=0;a[i]!=‘\0‘;i++) 36 { 37 sum=sum*10+a[i]-‘0‘; 38 if(sum>=p)break; 39 } 40 solve(sum,p); 41 } 42 return 0; 43 }
标签:des style blog http java color
原文地址:http://www.cnblogs.com/tom987690183/p/3862550.html