比赛 |
2025.10.18 |
评测结果 |
WWWAAAAAAA |
题目名称 |
WHZ 的数字 |
最终得分 |
70 |
用户昵称 |
梦那边的美好ME |
运行时间 |
0.055 s |
代码语言 |
C++ |
内存使用 |
3.73 MiB |
提交时间 |
2025-10-18 11:10:36 |
显示代码纯文本
#include <iostream>
#include <algorithm>
using namespace std;
using ull=unsigned long long;
ull count(ull x){
if (x==0) return 1;
ull res=1;
ull b=1;
while (b<=x){
ull p=x/(b*10);
ull d=(x/b)%10;
ull s=x%b;
if (d == 0){
res+=(p>0?(p-1)*b+s+1:0);
} else {
res+=p*b;
}
b*=10;
}
return res;
}
ull n,k;
ull tz,tg;
int main(){
// freopen("in.in","r",stdin);
// freopen("out.out","w",stdout);
freopen("whz_number.in","r",stdin);
freopen("whz_number.out","w",stdout);
while (cin>>n>>k){
tz=count(n);
if (k == tz){
cout<<0<<endl;
continue;
}
tg=tz-k;
ull left=0,right=n,ans=0;
bool found=0;
while (left<=right){
ull mid=left+(right-left)/2;
ull cnt=count(mid);
if (cnt==tg){
ans=mid;
found=1;
left=mid+1;
}else if (cnt<tg){
left=mid+1;
}else{
right=mid-1;
}
}
if (found){
cout<<ans+1<<endl;
} else {
cout<<0<<endl;
}
}
return 0;
}