建议加强数据
查看原帖
建议加强数据
1278301
jiayu114514楼主2025/2/8 13:28

第一个样例能过,第二个样例不过但是提交能AC,代码如下

#include<bits/stdc++.h>
using namespace std;
string toa(int n,int x){
	string ans="";
	do{
		int t=n%x;
		if(t>=0&&t<=9){
			ans+=t+'0';
		}
		else{
			ans+=t-10+'A';
		}
		n/=x;
	}
	while(n!=0);
	reverse(ans.begin(),ans.end());
	return ans;
}
int main(){
	int l,r;
	int ans=0;
	bool f=0;
	cin>>l>>r;
	for(int i=l;i<=r;i++){
		string a,b,c;
		a=toa(i,5);b=toa(i,7);c=toa(i,9);
		int len=max(a.size(),max(b.size(),c.size()));
		for(int j=1;j<len;j++){
			if(a[j]!='0'&&b[j]!='0'&&c[j]!='0'){
				f=1;
			}
			if(a[j]=='0'||b[j]=='0'||c[j]=='0'){
				f=0;
				break;
			}
		}
		if(f==1){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}
2025/2/8 13:28
加载中...