Codeforces Round #692 (Div. 2, based on Technocup 2021 Elimination Round 3) B. Fair Numbers 暴力

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
inputCopy
4
1
282
1234567890
1000000000000000000
outputCopy
1
288
1234568040
1000000000000000000
Note
Explanations for some test cases:

In the first test case number 1 is fair itself.
In the second test case number 288 is fair (it’s divisible by both 2 and 8). None of the numbers from [282,287] is fair, because, for example, none of them is divisible by 8.
交的纯暴力,一开始还会以为被hack,最后居然过综测了、

#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<assert.h>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
ll a[maxn],b[maxn];
void solve(){
	ll t;
    cin>>t;
    while(t--)
    {
       ll s;
        cin>>s;
        int i=0;
        while(1)
        {
            ll x=s+i++;
            ll tmp=x;
            ll flag=1;
            for(ll i=1;i<=9;i++){
                a[i]=0;
            }
            while(tmp){
                a[tmp%10]++;
                tmp/=10;
            }
            for(ll j=2;j<=9;j++){
                if(a[j]){
                    if(x%j!=0){
                        flag=0;
                        break;
                    }
                }
            }
            if(flag)
            {
                cout<<x<<endl;
                break;
            }
        }
    }
}
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	solve();
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值