Rhss @ 2022-09-28 13:17:42
#include <bits/stdc++.h>
using namespace std;
struct bigint{
int d[4000];
int len;
bigint(){
memset(d,0,sizeof(d));
len = 0;
}
};
int n;
bigint mulit(bigint a,int b){
bigint c;
int carry = 0;
for(int i = 0;i<a.len;++i){
int t = a.d[i] * b + carry;
c.d[c.len++] = t%10;
carry = t/10;
}
while(carry){
c.d[c.len++] = carry;
carry = 0;
}
return c;
}
int main(){
cin>>n;
int x,y;
while(n--){
cin>>x>>y;
bigint b1;
b1.len=1,b1.d[0]=1;
for(int i = 2;i<=x;++i){
b1 = mulit(b1,i);
}
int ans = 0;
for(int i = 0;i<b1.len;++i){
if(b1.d[i]==y){
ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
by xioachou @ 2022-10-19 14:33:53
我也是和你犯了一样的错误,那个乘的函数里面应该把carry一位一位压进数组的,不然如果carry是123,就会少判断了1或者2或者3的位数了。
by Lucas2024 @ 2022-10-24 20:33:46
#include<iostream>
#include<cstring>
using namespace std;
int a[2570],l,ans,t,n,m;
int main(){
int i,j;
cin>>t;
while(t){
t--;
cin>>n>>m;
ans=0;
memset(a,0,sizeof(a));
l=1;
a[0]=1;//初始化为1,不能为0,不然怎么乘都是0
for(i=2;i<=n;i++){
for(j=0;j<l;j++){
a[j]*=i;
}
for(j=0;j<l;j++){
if(a[j]>9){//进位
a[j+1]+=a[j]/10;
a[j]%=10;
}
}
while(a[l]!=0){//l+1若>0,长度++
if(a[l]>9){//再次判断进位
a[l+1]+=a[l]/10;
a[l]%=10;
}
l++;
}
}
while(l--){//当长度为0时,ans表示数字m的个数
if(a[l]==m){
ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
by Lucas2024 @ 2022-10-24 20:34:15
这是正解