CF1498A.GCD Sum

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 x≥nx \ge n such that \text{gcdSum}(x) \gt 1.

一个正整数的 \text{gcdSum} 定义为该整数与其各位数字之和的最大公约数。形式化地,对正整数 xx,有 \text{gcdSum}(x) = \gcd(x, \text{ } x \text{ 的各位数字之和})。其中 gcd⁡(a,b)\gcd(a, b) 表示 aa 与 bb 的最大公约数——即能同时整除 aa 和 bb 的最大整数 dd。

例如:\text{gcdSum}(762) = \gcd(762,\ 7 + 6 + 2) = \gcd(762,\ 15) = 3。

给定一个整数 nn,请找出满足 \text{gcdSum}(x) > 1 的最小整数 x≥nx \ge n。

输入格式

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

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

All test cases in one test are different.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

接下来是 tt 行,每行包含一个整数 nn(1≤n≤10181 \le n \le 10^{18})。

同一组测试中的所有测试用例互不相同。

输出格式

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

输出 tt 行,其中第 ii 行是一个整数,表示第 ii 个测试用例的答案。

输入输出样例

  • 输入#1

    3
    11
    31
    75

    输出#1

    12
    33
    75

说明/提示

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 $ \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 $ \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 $ \gt 1$. Hence, it is the answer.

我们来解释样例中的三个测试用例。

测试用例 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。

因此,大于等于 1111 且其 \text{gcdSum} > 1 的最小数是 1212。

测试用例 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。

因此,大于等于 3131 且其 \text{gcdSum} > 1 的最小数是 3333。

测试用例 3:n=75n = 75:

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

7575 的 \text{gcdSum} 已经大于 11,因此答案就是 7575。

输入解题思路,AI测评打分。不知道怎么写?

首页