比赛 2025.10.18 评测结果 AAAAAEEEEE
题目名称 WHZ 的数字 最终得分 50
用户昵称 梦那边的美好BP 运行时间 2.204 s
代码语言 C++ 内存使用 5.02 MiB
提交时间 2025-10-18 11:12:04
显示代码纯文本
#include <iostream>
using namespace std;
const int N = 2e6 + 6;
int a[N];
int cnt0(long long x) {
    if (a[x] != 0)
        return a[x];
    if (x == 0)
        return a[x] = 1;
    if (x / 10 == 0) {
        return a[x] = 0;
    }
    // int ans = 0;
    // while (x) {
    //     if (x % 10 == 0)
    //         ans++;
    //     x /= 10;
    // }
    return a[x] = cnt0(x / 10) + ((x % 10) == 0);
}
int main() {
    freopen("whz_number.in", "r", stdin);
    freopen("whz_number.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n, k;
    while (cin >> n >> k) {
        long long cnt = 0;
        while (true) {
            cnt += cnt0(n);
            if (cnt == k) {
                cout << n << endl;
                break;
            }
            n--;
        }
    }
    return 0;
}