Codeforces Round #692 (Div. 2) B. Fair Numbers(暴力枚举)

题目链接:https://codeforc.es/contest/1465/problem/B

We call a positive integer number fair if it is divisible by each of its nonzero digits. For example, 102 is fair (because it is divisible by 1 and 2), but 282 is not, because it isn’t divisible by 8. Given a positive integer n. Find the minimum integer x, such that n≤x and x is fair.

Input
The first line contains number of test cases t (1≤t≤103). Each of the next t lines contains an integer n (1≤n≤1018).

Output
For each of t test cases print a single integer — the least fair number, which is not less than n.

Example

input

4
1
282
1234567890
1000000000000000000

output

1
288
1234568040
1000000000000000000

分析

我们可以发现, fair number 之间相隔的距离并不是很远,所以可以直接暴力将答案算出来。

代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll N = 1e18;

int main()
{
	ll t;
	scanf("%lld",&t);
	while(t--)
	{
		ll begin;
		scanf("%lld",&begin);
		for(ll i=begin;i<=N;i++)
		{
			ll t = i;
			ll flag = 1;
			while(t)
			{
				ll x = t % 10;
				t /= 10;
				if(x == 0) continue;
				if(i % x != 0) flag = 0;
			}
			if(flag == 1)
			{
				printf("%lld\n",i);
				break;
			}
		}
	}
	
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值