标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3123
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cstdlib> 5 #include<cmath> 6 #include<algorithm> 7 #define inf 0x7fffffff 8 using namespace std; 9 typedef long long LL; 10 11 LL n,m; 12 char str[111]; 13 14 int main() 15 { 16 int t ;scanf("%d",&t) ; 17 while (t--) 18 { 19 scanf("%s%I64d",str,&m); 20 if (str[0]==‘0‘) {printf("%I64d\n",(LL)1%m);continue; } 21 LL sum=0,len=strlen(str); 22 for (LL i= len-7>=0 ? len-7 : 0 ;i<=len-1 ;i++) sum=sum*10+str[i]-‘0‘; 23 LL ans=1,a=1; 24 for (LL i=1 ;i<=sum && i<=m ;i++) 25 { 26 a=a*i%m; 27 ans=(ans+a)%m; 28 } 29 printf("%I64d\n",ans%m); 30 } 31 return 0; 32 }
标签:
原文地址:http://www.cnblogs.com/huangxf/p/4381818.html