1411B.md (1176B)
1 Source: https://codeforces.com/problemset/problem/1411/B 2 3 B. Fair Numbers 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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 \leq x$ and $x$ is fair. 22 23 Input 24 25 The first line contains number of test cases $t$ ($1 \leq t \leq 10^3$). Each of the next $t$ lines contains an integer $n$ ($1 \leq n \leq 10^{18}$). 26 27 Output 28 29 For each of $t$ test cases print a single integer — the least fair number, which is not less than $n$. 30 31 Example 32 33 Input 34 35 ``` 36 4 37 1 38 282 39 1234567890 40 1000000000000000000 41 ``` 42 43 Output 44 45 ``` 46 1 47 288 48 1234568040 49 1000000000000000000 50 ``` 51 52 Note 53 54 Explanations for some test cases: 55 56 * In the first test case number $1$ is fair itself. 57 * 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$.