fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define endl '\n'
  5. #define int long long
  6.  
  7. const int N = 2e5, oo = 2e18, MOD = 1e9+7;
  8.  
  9.  
  10. void solve() {
  11. int x, y; cin >> x >> y;
  12. string s = to_string(x);
  13. reverse(s.begin(), s.end());
  14. int mxZ = y - x;
  15. int ans = 0, sum = 0, need = 1, ten = 1;
  16. for (int i = 0; i < s.size(); i++) {
  17. sum += (ten * (s[i] - '0'));
  18. if (s[i] == '0') {
  19. int curZ = need - sum;
  20. if (curZ <= mxZ) ans = curZ;
  21. }
  22. need = need * 10 + 1;
  23. }
  24. cout << ans << endl;
  25. }
  26.  
  27.  
  28. signed main() {
  29. ios_base::sync_with_stdio(false);
  30. cin.tie(NULL); cout.tie(NULL);
  31. // #ifndef ONLINE_JUDGE
  32. // freopen("input.txt", "r", stdin);
  33. // freopen("output.txt", "w", stdout);
  34. // #endif
  35. int t; t = 1;
  36. cin >> t;
  37. while (t--) solve();
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
0