https://codeforces.com/contest/1465/problem/B
题意:给你个数字n,输出一个不小于n的数字x,使得x能整除x各个位上的数字(n就满足的话就输出n)。
读完题就能知道要干两件事,分离位数和判断整除,然后…就没有然后了。
(感觉我这样做有点费时间?最终耗时半秒左右…)
#include <bits/stdc++.h>
using namespace std;
#define qc std::ios::sync_with_stdio(0);
long long s[19];
int main() {
qc;
int t;
cin >> t;
while (t--) {
long long a;
long long aa = a;
cin >> a;
aa=a;
int k = 0;
while (a != 0) {
s[k] = a % 10;
a = a / 10;
k++;
}
a = aa;
int flag;
for (int i = 0; i < k; i++) {
if (s[i] != 0) {
if (a % s[i] != 0) {
while (1) {
flag = 1;
a++;
k = 0;
aa = a;
while (a != 0) {
s[k] = a % 10;
a = a / 10;
k++;
}
a = aa;
for (int j = 0; j < k; j++) {
if (s[j] != 0) {
if (a % s[j] != 0) {
flag = 0;
break;
}
}
}
if (flag == 1)
break;
}
}
}
}
cout << a << endl;
}
return 0;
}