lutaoquan2012 @ 2023-05-07 11:11:18
#include<bits/stdc++.h>
using namespace std;
//typedef long long ll;
struct Big{
int len,a[110];
Big(int x=0){
memset(a,0,sizeof(a));
for(len=1;x;len++) a[len]=x%10,x/=10;
len--;
}
int &operator[](int i) {
return a[i];
}
void flatten(int L){
len=L;
for(int i=1;i<=len;i++) a[i+1]+=a[i]/10,a[i]%=10;
while(a[len]==0) len--;
}
void print(int xx){
int nn=0;
if(1>len) len=1;
for(int i=len;i>=1;i--){
if(a[i]==xx) nn++;
}
cout<<nn<<endl;
//for(int i=len;i>=1;i--) cout<<a[i];
//cout<<endl;
}
};
Big operator+(Big a,Big b){
Big c;
int len=max(a.len,b.len);
for(int i=1;i<=len;i++) c[i]+=a[i]+b[i];
c.flatten(len+1);
return c;
}
Big operator*(Big a,int b){
Big c;
int len=a.len;
for(int i=1;i<=len;i++) c[i]=a[i]*b;
c.flatten(len+11);
return c;
}
int main(){
int n,m,x,f,l,cnt=0;
cin>>m;
while(m--){
cin>>n>>x;
Big factor(1);
for(int i=1;i<=n;i++){
factor=factor*i;
//ans=ans+factor;
}
factor.print(x);
}
return 0;
}
by gu33gu @ 2023-05-13 17:21:46
问题可能在于:Big里面的a数组开小了,这道题位数超级大,建议开到10^4
by dingding2008 @ 2023-05-13 20:46:41
呃,我做出来了,网上查过,数组开3010就行了
by lutaoquan2012 @ 2023-05-16 22:22:04
@gu33gu 谢谢大佬
by lutaoquan2012 @ 2023-05-16 22:22:19
@dingding2008 谢谢大佬
by lutaoquan2012 @ 2023-05-16 22:22:38
此贴结