数论题,分析一下就可以了
1 #include<set> 2 #include<map> 3 #include<list> 4 #include<queue> 5 #include<stack> 6 #include<string> 7 #include<cmath> 8 #include<ctime> 9 #include<vector> 10 #include<bitset> 11 #include<memory> 12 #include<utility> 13 #include<cstdio> 14 #include<sstream> 15 #include<iostream> 16 #include<cstdlib> 17 #include<cstring> 18 #include<algorithm> 19 using namespace std; 20 21 int n,m,k,t; 22 int a[2005][2005],f[2005][2005]; 23 24 int ff(){ 25 a[1][1]=a[1][0]=1; 26 for(int i=2;i<=2000;i++){ 27 a[i][0]=1; 28 for(int j=1;j<=i;j++){ 29 a[i][j]=(a[i-1][j]+a[i-1][j-1])%k; 30 } 31 } 32 for(int i=2;i<=2000;i++){ 33 for(int j=1;j<=i;j++){ 34 f[i][j]=f[i-1][j]+f[i][j-1]-f[i-1][j-1]; 35 if(a[i][j]==0){ 36 f[i][j]+=1; 37 } 38 } 39 f[i][i+1]=f[i][i]; 40 } 41 } 42 43 int main(){ 44 //freopen("problem.in","r",stdin); 45 //freopen("problem.out","w",stdout); 46 scanf("%d%d",&t,&k); 47 ff(); 48 while(t--){ 49 scanf("%d%d",&n,&m); 50 if(m>n){ 51 m=n; 52 } 53 printf("%d ",f[n][m]); 54 } 55 return 0; 56 }