Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define pb push_back
- #define pii pair<int, int>
- #define pll pair<ll, ll>
- #define el endl
- #define umi unordered_map<int, int>
- #define umll unordered_map<ll, ll>
- #define all(vect) vect.begin(), vect.end()
- #define reset(A) memset(A, 0, sizeof(A))
- #define approx(n) fixed << setprecision(n)
- using namespace std;
- const int mod = 1e9 + 7;
- ll sumOfDigits(ll n) {
- ll sum = 0;
- while(n) {
- sum += n % 10;
- n /= 10;
- }
- return sum;
- }
- void solve()
- {
- ll n, s;
- cin >> n >> s;
- if(sumOfDigits(n) <= s)
- {
- cout << 0 << el;
- return;
- }
- int i = 1;
- ll p = (ll)pow(10, 1);
- while(p < n) {
- i++;
- p = (ll)pow(10, i);
- }
- if(i % 2 == 0) {
- p++;
- }
- // cout << p - n << el;
- p -= n;
- ll ind = 1;
- while(true) {
- ll te = (ll)pow(10, ind);
- if(sumOfDigits(n + p % te) <= s) {
- cout << p % te << el;
- return;
- }
- ind++;
- }
- }
- int main()
- {
- int t = 1;
- cin >> t;
- // cin.ignore();
- while (t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement