fork download
  1. #include <bits/stdc++.h>
  2. #include<iostream>
  3. #include<bitset>
  4. #include<unordered_set>
  5. #include<unordered_map>
  6. #include<algorithm>
  7. using namespace std;
  8. #define int long long
  9. #define ld long double
  10. #define ull unsigned long long
  11. #define endl '\n'
  12. #define pb push_back
  13. #define pf push_front
  14. #define sz(s) (int)(s.size())
  15. #define all(b) b.begin(),b.end()
  16. #define allr(b) b.rbegin(),b.rend()
  17. #define pq priority_queue
  18. #define mp make_pair
  19. #define S second
  20. #define F first
  21. #define cin(b) for(auto &it:b)cin>>it;
  22. #define cinG(grid) for(auto &r:grid) for(auto &c:r)cin>>c;
  23. #define cout(b) for(auto &it:b)cout<<it<<" ";
  24. #define ret return
  25. typedef vector<int> vi;
  26. typedef vector<vi> vvi;
  27. typedef vector<bool> vb;
  28. typedef vector<vb> vvb;
  29. typedef vector<char> vc;
  30. typedef vector<vc> vvc;
  31. typedef vector<pair<int, int>> vpi;
  32. typedef vector<vector<pair<int, int>>> vvpi;
  33.  
  34. int oo = 0x3f3f3f3f3f;
  35. int num;
  36. const int mod = 1e9 + 7;
  37. //solve
  38.  
  39. int di[8]{ 1 , -1 , 0 , 0 , 1 , 1 , -1 , -1 };
  40. int dj[8]{ 0 , 0 , 1 , -1 , 1 , -1 , -1 , 1 };
  41. char dv[4]{ 'D','U','R','L' };
  42. const int N = 2e5+5;
  43. const int SS = 1e3 + 5;
  44.  
  45. int in;
  46. int k;
  47.  
  48.  
  49. int sumDigits(int num) {
  50. int sum=0;
  51. while (num)
  52. sum+=num%10, num/=10;
  53.  
  54. ret sum;
  55. }
  56. bool can(int x0) {
  57. ret x0-sumDigits(x0)>=k;
  58. }
  59. void Zero() {
  60. cin>>in>>k;
  61.  
  62. int l=0,r=in;
  63. int x0=-oo;
  64. while (l<=r) {
  65. int mid=(l+r)>>1;
  66. if (can(mid)) {
  67. x0=mid;
  68. r=mid-1;
  69. }else {
  70. l=mid+1;
  71. }
  72.  
  73. }
  74.  
  75. if (x0==-oo) {
  76. cout<<0<<endl;
  77. }else {
  78. cout<<in-x0+1<<endl;
  79. }
  80.  
  81. }
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. void Solve() {
  89. int tc = 1;
  90.  
  91. //put pre processing functions here
  92. /*freopen("connect.in", "r", stdin);
  93. freopen("connect.out", "w", stdout);*/
  94. //cin >> tc;
  95. while (tc--) {
  96. Zero();
  97. }
  98. }
  99.  
  100. signed main() {
  101. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); // Not needed with scanf/printf
  102. Solve();
  103. return 0;
  104. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
1