题目
题意:定义一个数为Fari number,如果它能被它的每一位数的数字整除。给定数n,求不小于n的最小fair number。
思路:由于{1,2,3,…,9}的最小公倍数是2520,因此找ans是可以暴力找的。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mx = 1e18;
bool check(ll x) {
ll a = x;
int mp[10];
memset(mp, 0, sizeof(mp));
while (a) {
int num = a % 10;
a /= 10;
if (num) mp[num] = 1;
}
for (int i = 2; i < 10; ++i) {
if (!mp[i]) continue;
if (x % i != 0) return false;
}
return true;
}
int main() {
int t;
scanf("%d", &t);
while(t--) {
ll n, x;
scanf("%lld", &n);
for (x = n; !check(x); ++x);
printf("%lld\n", x);
}
}