G - 这么短的题面一定不会很难吧
Description
你有一个整数 nn 和 ss 。一步中你可以使 nn 增加 11(n= n+1n=n+1)。找到最小步数使得 nn 的每一位加起来小于或等于 ss。
Input
第一行包含一个整数 tt (1\le t\le 2·10^41≤t≤2⋅10
4
)——测试数据组数。随后有t组测试数据
每组测试数据包含两个整数 nn 和 ss (1\le n\le 10^{15};1\le s \le 162)(1≤n≤10
15
;1≤s≤162)。
Output
每组测试数据输出答案:将n变为每一位数字的和小于等于 ss 的最小步数。
Sample
Input
5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1
Output
8
0
500
2128012501878
899999999999999999
Hint
对于第三组数据:n = 500 + 500 = 1000 => 1+0+0+0<4n=500+500=1000=>1+0+0+0<4
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL x[20];
void get_x() {
x[0] = 1;
for (int i = 1; i <= 19; i++) {
x[i] = x[i - 1] * 10;
}
}
int main() {
ios::sync_with_stdio(false);
LL T, n, s, ans, t, k, i, sum;
int a[20];
get_x();
cin >> T;
while (T--) {
cin >> n >> s;
k = 0, t = n, sum = 0;
while (t) {
a[++k] = t % 10;
sum += t % 10;
t /= 10;
}
if (sum <= s)
ans = 0;
else {
for (i = k; i > 0; i--) {
if (s > a[i]) {
s -= a[i];
} else if (s == a[i]) {
s -= a[i];
break;
} else
break;
}
ans = x[i] - n % x[i];
}
cout << ans << '\n';
}
}