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;
}