#include<bits/stdc++.h>//小黑子
using namespace std;//ikun
typedef long long ll;//简写
typedef int itn;//防手滑
const int mx=1e5+10;//mx
struct bign{
int l,s[mx];
bign(){l=1, memset(s,0,sizeof(s));}
bign(const int x){*this=x;}
bign operator =(const int x){
char str[25];
sprintf(str,"%d",x);
return *this=str;
}
bign operator =(const char *num){
l=strlen(num);
memset(s,0,sizeof(s));
for(int i=1;i<=l;i++) s[i]=num[l-i]-'0';
return *this;
}
bign operator +(const bign b){
int len=l>b.l?l:b.l;
bign c;
for(int i=1;i<=len;i++) c.s[i]+=s[i]+b.s[i], c.s[i+1]+=c.s[i]/10, c.s[i]%=10;
c.l=len+1;
c.clean();
return c;
}
bign operator -(const bign b){
bign c;
for(int i=1;i<=l;i++){
if(s[i]<b.s[i]) s[i]+=10, s[i+1]--;
c.s[i]=s[i]-b.s[i];
}
c.l=l;
c.clean();
return c;
}
bign operator *(const bign b){
bign c;
for(int i=1;i<=l;i++) for(int j=1;j<=b.l;j++) c.s[i+j-1]+=s[i]*b.s[j], c.s[i+j]+=c.s[i+j-1]/10, c.s[i+j-1]%=10;
c.l=l+b.l+1;
c.clean();
return c;
}
bign operator /(const bign b){
bign c,f=0;
for(int i=l;i>=1;i--){
f=f*10, f.s[1]=s[i];
while(f>=b) f=f-b,c.s[i]++;
}
c.l=l;
c.clean();
return c;
}
bign operator %(const bign b){
bign c,f=0;
for(int i=l;i>=1;i--){
f=f*10, f.s[1]=s[i];
while(f>=b) f=f-b,c.s[i]++;
}
f.l=l;
f.clean();
return f;
}
void clean(){while(l>1&&!s[l]) l--;}
bool operator >(const bign b){
if(l!=b.l) return l>b.l;
for(int i=l;i>=1;i--) if(s[i]!=b.s[i]) return s[i]>b.s[i];
return false;
}
bool operator <(const bign b){
if(l!=b.l) return l<b.l;
for(int i=l;i>=1;i--) if(s[i]!=b.s[i]) return s[i]<b.s[i];
return false;
}
bool operator ==(const bign b){
return !(*this>b)&&!(*this<b);
}
bool operator >=(const bign b){
return !(*this<b);
}
bool operator <=(const bign b){
return !(*this>b);
}
};
istream& operator >>(istream &in, bign &b){
string str;
in>>str;
b=str.c_str();
return in;
}
ostream& operator <<(ostream &out, const bign &b){
for(int i=b.l;i>=1;i--) out<<b.s[i];
return out;
}
bign fun(bign x){
bign s=1;
for(bign i=1;i<=x;i=i+1) s=s*i;
return s;
}
bign c(bign n, bign m){
return fun(n)/(fun(m)*fun(n-m));
}
bign __min(bign a, bign b){
if(a<=b) return a;
else return b;
}
int main(){
bign n,m,k,t,cnt;
cin>>t>>k;
for(bign i=t-1;i>=1;i=i-1){
cin>>n>>m;
for(bign i=1;i<=n;i=i+1) for(bign j=1;j<=__min(m,i);j=j+1) if(c(i,j)%k==0) cnt=cnt+1;
}
cout<<cnt<<endl;
return 0;
}
求助!!!
WA+TLE