返回题解分享
讨论 / 题解分享/ 帖子详情

幸运数字(结果填空) - 题解

#include <iostream>

using namespace std;

bool check(int x,int n)
{
	int q=x;
	int t=0,res=0;
	while(x)
	{
		t=x%n;
		x/=n;
		res+=t;
	}
	return q%res==0;
}

int main()
{
	int n;
	cin>>n;
	int cnt=0;
	for(int i=1;;i++)
	{
		int x=i;
		if(check(x,2)&&check(x,10)&&check(x,8)&&check(x,16)) cnt++;
		if(cnt==n)
		{
			cout<<x;
			break;
		}
	}
	return 0;
}
0 回复 0 转发 0 喜欢 0 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!