CF899D 题解
Register_int · · 题解
只有最高位能影响方案数。所以首先算出最多能算出几个
AC 代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, ans, t = 1;
ll x, l, r;
int main() {
scanf("%lld", &n);
while (t * 5 <= n) t *= 10;
for (int i = 1; i <= 9; i++) {
x = i * t - 1, l = max(1ll, x - n), r = min(n, x - 1);
if (l < r) ans += (r - l + 1) >> 1;
}
printf("%lld", ans);
}