标签:
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; char s[110000]; int main() { long long t,n,md,a,i,sum,l; cin>>t; while(t--) { cin>>s>>md; l = strlen(s); n = 0; if(l>7)n = md; else for(i = 0;i<l;i++) n = n*10+s[i]-‘0‘; sum = a = 1; for(i = 1;i<=n;i++) { a = (a*i)%md; sum = (sum+a)%md; } sum%=md; cout<<sum<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/wos1239/p/4564473.html