-
-
Save MinecraftFuns/1b9c14c48f3b97ef0569118ab4d5b8f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace sol | |
{ | |
long long a, b; | |
const int N = 60; | |
long long ten[N], f[N]; | |
long long cnt_a[N], cnt_b[N]; | |
long long num[N]; | |
inline void init() | |
{ | |
ten[0] = 1; | |
for (register int i = 1; i <= N - 5; i++) | |
{ | |
f[i] = f[i - 1] * 10 + ten[i - 1]; | |
ten[i] = 10 * ten[i - 1]; | |
} | |
} | |
inline int parse_num(long long x) | |
{ | |
int res = 0; | |
memset((num), 0, sizeof((num))); | |
while (x) | |
{ | |
num[++res] = x % 10; | |
x /= 10; | |
} | |
return res; | |
} | |
inline void solve(long long x, long long *cnt) | |
{ | |
int len = parse_num(x); | |
for (register int i = len; i > 0; i--) | |
{ | |
for (register int j = 0; j < 10; j++) | |
{ | |
cnt[j] += f[i - 1] * num[i]; | |
} | |
for (register int j = 0; j < num[i]; j++) | |
{ | |
cnt[j] += ten[i - 1]; | |
} | |
long long Num = 0; | |
for (register int j = i - 1; j > 0; j--) | |
{ | |
Num = Num * 10 + num[j]; | |
} | |
cnt[num[i]] += Num + 1; | |
cnt[0] -= ten[i - 1]; | |
} | |
} | |
inline void main() | |
{ | |
init(); | |
int T; | |
io::read(T); | |
for (register int _ = 1; _ <= T; _++) | |
{ | |
memset((cnt_a), 0, sizeof((cnt_a))); | |
memset((cnt_b), 0, sizeof((cnt_b))); | |
io::read(a), io::read(b); | |
solve(a - 1, cnt_a); | |
solve(b, cnt_b); | |
printf("Case %d: %lld\n", _, cnt_b[0] - cnt_a[0]); | |
} | |
} | |
} // namespace sol | |
int main() | |
{ | |
sol::main(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment