比赛 |
2025.10.18 |
评测结果 |
WWWAAWWWWW |
题目名称 |
WHZ 的数字 |
最终得分 |
20 |
用户昵称 |
淮淮清子 |
运行时间 |
0.051 s |
代码语言 |
C++ |
内存使用 |
3.68 MiB |
提交时间 |
2025-10-18 11:09:39 |
显示代码纯文本
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;
ll count(ll x){
if(x < 0) return 0;
if(x == 0) return 1;
ll ans = 1, b = 1;
while(b <= x){
ll u = x % b, h = x / (b * 10);
ll cur = (x / b) % 10;
if(cur == 0) ans += (h - 1) * b + u + 1;
else ans += h * b;
b *= 10;
}
return ans;
}
ll n, k;
int main(){
freopen("whz_number.in", "r", stdin);
freopen("whz_number.out", "w", stdout);
cin.tie(0); ios::sync_with_stdio(0);
while(cin >> n >> k){
ll tot = count(n);
ll tag = tot - k;
ll l = 0, r = n, ans = -1;
while(l <= r){
ll mid = (l + r) / 2;
if(count(mid) <= tag) ans = mid, l = mid + 1;
else r = mid - 1;
}
cout << ans + 1 << '\n';
}
return 0;
}