fork download
  1.  
  2.  
  3. #ifdef Asaad
  4. #include "cp.h"
  5. #define debug(...) _dbg_many(#__VA_ARGS__, __VA_ARGS__)
  6. #define here cerr << "LINE " << __LINE__ << "\n"
  7. #else
  8. #include <bits/stdc++.h>
  9. using namespace std;
  10. /*
  11.   #include <ext/pb_ds/assoc_container.hpp>
  12.   #include <ext/pb_ds/tree_policy.hpp>
  13.   using namespace __gnu_pbds;
  14.   template<class T>
  15.   using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  16.   */
  17. #define debug(...)
  18. #define here
  19. #endif
  20.  
  21.  
  22.  
  23. #define ll long long
  24. #define int long long
  25. #define all(x) x.begin(), x.end()
  26. #define siz(x) ((int)x.size())
  27. #define yes cout << "YES\n"
  28. #define no cout << "NO\n"
  29. #define f first
  30. #define s second
  31. #define eb emplace_back
  32. #define pb push_back
  33.  
  34.  
  35. const int mod = 1e9+7;
  36. const int N = 200009;
  37. const long long inf = 1e18+12309138;
  38. double eps = 1e-9;
  39.  
  40.  
  41.  
  42.  
  43.  
  44. void tc () {
  45. //nb=
  46. int x, y;
  47. cin >> x >> y;
  48. y-= x;
  49. if ( x == 0 ) {
  50. cout << min(1LL, y) << "\n";
  51. return;
  52. }
  53. int ans = 0;
  54. vector<int> pw(19, 1), mo(19, 1);
  55. for (int i=1; i<19; i++) {
  56. pw[i] = pw[i-1]*10;
  57. mo[i] = mo[i-1]*10+1;
  58. }
  59. for (int i=0; i<19; i++) {
  60. int bye = x/pw[i];
  61. if ( bye == 0 ) break;
  62. if ( bye%10 != 0 ) continue;
  63. bye*=pw[i];
  64. bye+= mo[i];
  65. int hi = min(bye-x, pw[i]+ans);
  66. if ( hi <= y ) {
  67. ans = hi;
  68. } else break;
  69. }
  70. cout << ans << "\n";
  71.  
  72.  
  73.  
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80. signed main () {
  81. ios::sync_with_stdio(false);
  82. cin.tie(0);
  83. //freopen( "input.txt", "r", stdin );
  84. //freopen( "output.txt", "w", stdout );
  85. //cout << fixed << setprecision(9);
  86. //pre();
  87. int t=1;
  88. cin >> t;
  89.  
  90. for (int i=1; i<=t; i++) {
  91. #ifdef Asaad
  92. auto start = chrono::high_resolution_clock::now();
  93. //cout << "---Case " << i << " Start---\n\n";
  94. #endif
  95.  
  96. tc();
  97.  
  98.  
  99. #ifdef Asaad
  100. auto end = chrono::high_resolution_clock::now();
  101. //cout << "---Case " << i << " End---\n";
  102. cerr << "Time #" << i << ": " << chrono::duration_cast<chrono::milliseconds>(end - start).count() << "ms" << endl;
  103. //cout << "--------------\n";
  104. #endif
  105. }
  106. }
  107.  
  108.  
  109.  
  110.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
0