-
Notifications
You must be signed in to change notification settings - Fork 10
/
1409D.cpp
58 lines (54 loc) · 1.02 KB
/
1409D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define INF 1e18
#define MOD 1000000007
#define Vi vector<ll>
#define Vs vector<string>
#define VI vector<vector<ll> >
#define PII pair<ll,ll>
#define PSI pair<string,ll>
#define PB push_back
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
int DX[] = {0,-1,-1,-1,0,1,1,1};
int DY[] = {-1,-1,0,1,1,1,0,-1};
ll sum(ll n)
{
ll s = 0;
while(n)
{
s += n%10;
n/=10;
}
return s;
}
int main()
{
fast;
ll t;
cin >> t;
while(t--)
{
ll n,s;
cin >> n >> s;
if(sum(n)<=s )
cout << 0 << '\n';
else{
ll p = 1;
ll ans = 0;
for(int i=0;i<19;i++)
{
ll dig = (n/p)%10;
ll add = ((10-dig)%10) * p;
ans += add;
n += add;
if( sum(n)<=s )
break;
p*=10;
}
cout << ans << '\n';
}
}
}