fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. const int MOD = 1e9 + 7;
  7.  
  8. ll dp(ll a){
  9. string s = to_string(a);
  10.  
  11. ll sol = 0;
  12. ll tmp = 1;
  13. for(int i = 0; i < s.size() - 1; i++){
  14. tmp *= 10;
  15. }
  16. ll g = s[0] - '0' - 1;
  17. // sol += (tmp * g * (g + 1) / 2);
  18. for(int j = 1; j < (int)s.size(); j++){
  19. ll tmp = 1;
  20.  
  21. ll ans = 0;
  22. for(int i = 0; i < (int)s.size() - 1; i++)tmp *= 10;
  23. for(int i = 0; i < j; i++){
  24. tmp /= 10;
  25. if(s[i] == '0'){
  26. tmp *= ('9' - s[i] + 1);
  27. continue;
  28. }
  29. tmp *= (s[i] - '0');
  30. ans += tmp;
  31. tmp /= (s[i] - '0');
  32. tmp *= ('9' - s[i] + 1);
  33. }
  34. sol += ans;
  35.  
  36. }
  37. return sol;
  38.  
  39.  
  40.  
  41. }
  42.  
  43. void solve(){
  44. ll a, b;
  45. cin >> a >> b;
  46. ll g = dp(b);
  47. ll h = dp(a);
  48.  
  49. string s = to_string(b);
  50. ll tmp = 0;
  51. for(auto x: s){
  52. tmp += (x - '0');
  53. }
  54. cout << g << " " <<h << "\n";
  55. cout << g - h + tmp << "\n";
  56. }
  57.  
  58. int main(){
  59. ios_base::sync_with_stdio(false);
  60. cin.tie(nullptr);
  61.  
  62. int t = 1;
  63. cin >> t;
  64.  
  65. for(int i = 1; i <= t; i++){
  66. solve();
  67. }
  68. return 0;
  69. }
Success #stdin #stdout 0.01s 5264KB
stdin
3
0 10
28 31
1234 56789
stdout
1 0
2
3 2
5
32280 876
31439