#include<bits/stdc++.h>
#define MAXN 1005
typedef long long ll;
ll c[2010][2010];
int t,k,m,n;
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin>>t>>k;
for(int i=0;i<=2000;i++){
c[i][0]=c[i][i]=1;
for(int j=1;j<i;j++){
c[i][j]=(c[i-1][j]+c[i-1][j-1])%k;
}
}
while(t--){
int ans=0;
cin>>n>>m;
for(int i=0;i<=n;i++){
for(int j=0;j<=min(i,m);j++){
ans+=c[i][j]==0;
}
}
cout<<ans<<endl;
}
return 0;
}
95pts 求助