A. Divisibility Problem

You are given two positive integers aa and bb. In one move you can increase aa by 11 (replace aa with a+1a+1). Your task is to find the minimum number of moves you need to do in order to make aa divisible by bb. It is possible, that you have to make 00 moves, as aa is already divisible by bb. You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1t1041≤t≤104) — the number of test cases. Then tt test cases follow.

The only line of the test case contains two integers aa and bb (1a,b1091≤a,b≤109).

Output

For each test case print the answer — the minimum number of moves you need to do in order to make aa divisible by bb.

题目问a加多少可以整除b,直接取个余然后用b减就可以了(注意判断刚好整除的情况)

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;
#define INF 99999999 
#define MAXN 100
 
int m, n, t;
 
 
int main() {
    cin >> t;
    while (t--) {
        int a, b;
        cin >> a >> b;
        int x = a % b;
        if(x!=0)
        x = b - x;
        
 
        cout << x << endl;
    }
 
 
 
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Vetsama/p/12578748.html