0分求助
查看原帖
0分求助
490821
chenqimeng楼主2022/9/25 16:17

我问问我哪错了。

看着没问题啊。

#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	int n;
	cin>>n;
	for(int sd=1;sd<=n;sd++){
		int ans[10000]={0},ls[10000]={0};
		int s,a,l=1,d=0;
		cin>>s>>a;
		ans[1]=1;
		for(int i=2;i<=s;i++){
			int p=false;
			for(int j=1;j<=l;j++){
				ls[j]+=ans[j]*i;
				if(ls[j]>=10){
					if(j==l)p=true;
					ls[j+1]+=ls[j]/10;
					ls[j]%=10;
				}
			}
			if(p==true)l++;
			for(int j=1;j<=l;j++){
				ans[j]=ls[j];
				ls[j]=0;
			}
			for(int j=l;j>=1;j--)cout<<ans[j];
			cout<<endl;
		}
		for(int i=1;i<=l;i++)if(ans[i]==a)d++;
		cout<<d<<endl;
	} 
}

2022/9/25 16:17
加载中...