第一周题单
A - Simple Design (CodeForces - 1884A)
A positive integer is called k-beautiful, if the digit sum of the decimal representation of this number is divisible by k†. For example, 9272 is 5-beautiful, since the digit sum of 9272 is 9+2+7+2=20.
You are given two integers x and k. Please find the smallest integer y≥x which is k-beautiful.
† An integer n is divisible by k if there exists an integer m such that n=k⋅m.
Input
Each test contains multiple test cases. The first line contains the number of test cases t ( 1 ≤ t ≤ 1 0 4 ) t(1≤t≤10^4) t(1≤t≤104). The description of the test cases follows.
The only line of each test case contains two integers x x x and k ( 1 ≤ x ≤ 1 0 9 , 1 ≤ k ≤ 10 ) k(1≤x≤10^9, 1≤k≤10) k(1≤x≤109,1≤k≤10).
Output
For each test case, output the smallest integer y ≥ x y≥x y≥x which is k k k-beautiful.
simple1
Input
6
1 5
10 8
37 9
777 3
1235 10
1 10
Output
5
17
45
777
1243
19
Note
In the first test case, numbers from 1 to 4 consist of a single digit, thus the digit sum is equal to the number itself. None of the integers from 1 to 4 are divisible by 5.
In the fourth test case, the digit sum of 777 is 7+7+7=21 which is already divisible by 3.
题目大意
从 x x x开始找到一个每位数之和能被 k k k整除的数
题解思路
从 x x x开始遍历直到找到为止
代码部分(cpp)#include <iostream>
using namespace std;
bool check(int num, int k)
{
int total = 0;
while (num > 0)
{
total += num % 10;
num /= 10;
}
if (total % k == 0)
return 1;
else
return 0;
}
void solution()
{
int t;
cin >> t;
while (t--)
{
int x, k;
cin >> x >> k;
while (1)
{
if (check(x, k))
{
cout << x << endl;
break;
}
else
x++;
}
}
}
int main(int argc, char const *argv[])
{
solution();
return 0;
}
刚开始学习,欢迎指正