显示代码纯文本
//#include<bits/stdc++.h>
//using namespace std;
//unsigned long long n,k;bool kk=0;
//void check(unsigned long long t){
// int sum=0;
// while(t>0){
// if(t%10==0){
// sum++;
// k--;
// }
// t/=10;
// }
//}
//int main(){
// while(cin>>n>>k){
// while(k){
// if(n==0){
// k--;
// cout<<n<<"\n";
// kk=1;
// break;
// }
// check(n);
// n--;
// }
// if(kk==1)continue;
// cout<<n+1<<"\n";
// }
// return 0;
//}
#include<bits/stdc++.h>
using namespace std;
// 计算一个数字中包含的0的个数
int countZeros(unsigned long long x) {
if (x == 0) return 1; // 数字0本身包含1个0
int cnt = 0;
while (x > 0) {
if (x % 10 == 0) cnt++;
x /= 10;
}
return cnt;
}
int main() {
unsigned long long n, k;
while (cin >> n >> k) {
unsigned long long current = n;
unsigned long long totalZeros = 0;
// 从n开始往小找,累计0的个数
while (current >= 0) {
totalZeros += countZeros(current);
// 如果累计的0个数等于k,找到解
if (totalZeros == k) {
break;
}
// 如果累计的0个数超过k,说明当前数字太小了
if (totalZeros > k) {
current++; // 回退一步
break;
}
if (current == 0) break; // 防止下溢
current--;
}
// 最终调整确保totalZeros == k
while (current <= n && totalZeros > k) {
totalZeros -= countZeros(current);
current++;
}
cout << current << "\n";
}
return 0;
}