Simple Design (CodeForces - 1884A)

第一周题单

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(1t104). 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(1x109,1k10).

Output

For each test case, output the smallest integer y ≥ x y≥x yx 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;
}

刚开始学习,欢迎指正

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值