Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. ll l, r;
  2.     cin >> l >> r;
  3.     ll f = l <= 9;
  4.     ll num = 9;
  5.     ll ans = 0;
  6.     ll cnt = 1;
  7.     while (r >= num)
  8.     {
  9.         r -= num;
  10.         ans += num;
  11.         num = num * 10 + 9;
  12.         cnt++;
  13.     }
  14.     if (r) ans += r / cnt;
  15.     num = 9;
  16.     cnt = 1;
  17.     ll ans1 = 0;
  18.     while (l >= num)
  19.     {
  20.         l -= num;
  21.         ans1 += num;
  22.         num = num * 10 + 9;
  23.         cnt++;
  24.     }
  25.     if (l) {
  26.         ans1 += l / cnt;
  27.         if (l % cnt && l > 1) ans1++;
  28.     }
  29.     cout << ans - ans1 + f;
  30.     return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement