A. Divisibility Problem(水题)Codeforces Round #629 (Div. 3)
原理链接:https://codeforces.com/contest/1328/problem/A
测试样例:
Input
5
10 4
13 9
100 13
123 456
92 46
Output
2
5
4
333
0
题意: 给你一个整数a和b,a每次都可以进行一次+1操作,问整数a至少要经过多少次操作才能够整除b。
解题思路: 一道很简单的题,利用计算机的整数整除机制,我们直接让 a / b a/b a/b看看是否能整除,若不能,则存储这个值,再加1乘以b之后获得的值即为a经过最少操作次数变为b的倍数的值,那么直接用这个值减去a就行。
AC代码:
/*
*邮箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h> //POJ不支持
#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
int t,a,b;
while(cin>>t){
while(t--){
cin>>a>>b;
int t=a/b;
if(b*t==a){
cout<<0<<endl;
}
else{
cout<<b*(t+1)-a<<endl;
}
}
}
return 0;
}