CF1498A.GCD Sum

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

GCD Sum

The \text{gcdSum} of a positive integer is the gcdgcd of that integer with its sum of digits. Formally, \text{gcdSum}(x) = gcd(x, \text{ sum of digits of } x) for a positive integer xx. gcd(a,b)gcd(a, b) denotes the greatest common divisor of aa and bb — the largest integer dd such that both integers aa and bb are divisible by dd.

For example: \text{gcdSum}(762) = gcd(762, 7 + 6 + 2)=gcd(762,15) = 3.

Given an integer nn, find the smallest integer xnx \ge n such that \text{gcdSum}(x) \gt 1.

Input

The first line of input contains one integer tt (1t104)(1 \le t \le 10^4) — the number of test cases.

Then tt lines follow, each containing a single integer nn (1n1018)(1 \le n \le 10^{18}).

All test cases in one test are different.

Output

Output tt lines, where the ii-th line is a single integer containing the answer to the ii-th test case.

Note

Let us explain the three test cases in the sample.

Test case 1: n=11n = 11:

\text{gcdSum}(11) = gcd(11, 1 + 1) = gcd(11,\ 2) = 1.

\text{gcdSum}(12) = gcd(12, 1 + 2) = gcd(12,\ 3) = 3.

So the smallest number 11\ge 11 whose gcdSumgcdSum >1\gt 1 is 1212.

Test case 2: n=31n = 31:

\text{gcdSum}(31) = gcd(31, 3 + 1) = gcd(31,\ 4) = 1.

\text{gcdSum}(32) = gcd(32, 3 + 2) = gcd(32,\ 5) = 1.

\text{gcdSum}(33) = gcd(33, 3 + 3) = gcd(33,\ 6) = 3.

So the smallest number 31\ge 31 whose gcdSumgcdSum >1\gt 1 is 3333.

Test case 3:  n=75\ n = 75:

\text{gcdSum}(75) = gcd(75, 7 + 5) = gcd(75,\ 12) = 3.

The \text{gcdSum} of 7575 is already >1\gt 1. Hence, it is the answer.

Samples

3
11
31
75
12
33
75

在线编程 IDE

建议全屏模式获得最佳体验