CodeCraft-21 and Codeforces Round 711 (Div. 2)
A
GCD Sum
Codeforces
800
原题
←B →
翻译中…

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

翻译中…

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

翻译中…

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

翻译中…

Input

翻译中…

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

翻译中…

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

翻译中…

All test cases in one test are different.

翻译中…

Output

翻译中…

Output $t$ lines, where the $i$-th line is a single integer containing the answer to the $i$-th test case.

翻译中…

Note

翻译中…

Let us explain the three test cases in the sample.

翻译中…

Test case 1: $n = 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 $\ge 11$ whose $gcdSum$ $ \gt 1$ is $12$.

翻译中…

Test case 2: $n = 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 $\ge 31$ whose $gcdSum$ $ \gt 1$ is $33$.

翻译中…

Test case 3: $\ n = 75$:

翻译中…

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

翻译中…

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

翻译中…

样例

Input #1
3
11
31
75
Output #1
12
33
75
InputCopy OutputCopy
题目信息
题号
1498A
时间限制
1 s
内存限制
256 MB
标签
暴力
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。