个人博客链接:https://blog.nuoyanli.com/2020/03/27/codeforces1328a/
题目链接
http://codeforces.com/contest/1328/problem/A
题意
组数据,每次给你两个数 ,对于一组 ,问你至少使 增大多少,才可以被 整除。
思路
- 思路 :若 直接输出 否则考虑 ,即 ,所以 ,要求的是至少的次数,又于是倍数递增,所以遍历最小的 即可,时间复杂度是允许的。
- 思路 :若 输出 ,否则输出 即可。
参考代码
- 参考代码 :
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define PB push_back
#define FI first
#define SE second
#define m_p(a, b) make_pair(a, b)
const double pi = acos(-1.0);
const double eps = 1e-9;
typedef long long LL;
const int N = 1e6 + 10;
const int M = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double f = 2.32349;
void solve() {
IOS;
int t;
cin >> t;
while (t--) {
LL a, b;
cin >> a >> b;
if (b >= a) {
cout << b - a << endl;
} else {
int k = a / b;
while (k * b < a) {
k++;
}
cout << k * b - a << endl;
}
}
}
signed main() {
solve();
return 0;
}
- 参考代码 :
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define PB push_back
#define FI first
#define SE second
#define m_p(a, b) make_pair(a, b)
const double pi = acos(-1.0);
const double eps = 1e-9;
typedef long long LL;
const int N = 1e6 + 10;
const int M = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double f = 2.32349;
void solve() {
IOS;
int t;
cin >> t;
while (t--) {
LL a, b;
cin >> a >> b;
if (a == b) {
cout << 0 << endl;
} else {
cout << b - (a - (a / b) * b) << endl;
}
}
}
signed main() {
solve();
return 0;
}