Saleh127

CF 1409D

Sep 5th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; while(t--)
  5. ll sd(ll x)
  6. {
  7. ll r=0;
  8. while(x)
  9. {
  10. r+=x%10;
  11. x/=10;
  12. }
  13. return r;
  14. }
  15.  
  16. int main()
  17. {
  18. ios_base::sync_with_stdio(0);
  19. cin.tie(0);
  20. cout.tie(0);
  21.  
  22. test
  23. {
  24. ll n,s,a=0,c,d,i,j,k,lastd;
  25.  
  26. cin>>n>>s;
  27. if(sd(n)<=s)
  28. {
  29. cout<<0<<endl;
  30. continue;
  31. }
  32. c=1;
  33. for(i=0; i<=18; i++)
  34. {
  35.  
  36. lastd=(n/c)%10;
  37. d=c*((10-lastd)%10);
  38. n+=d;
  39. a+=d;
  40. if(sd(n)<=s)
  41. {
  42. cout<<a<<endl;
  43. break;
  44. }
  45. c*=10;
  46. }
  47. }
  48. return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment