QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#414188#7996. 报数 IVAcetaminophenTL 0ms3500kbC++111022b2024-05-18 16:41:312024-05-18 16:41:32

Judging History

你现在查看的是最新测评结果

  • [2024-05-18 16:41:32]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3500kb
  • [2024-05-18 16:41:31]
  • 提交

answer

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const int MOD = 1e9+7;

// 计算数字n的各位数字之和
int digitSum(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

// 计算g(n, k)函数
int g(int n, int k) {
    for (int i = 0; i < k; ++i) {
        n = digitSum(n);
    }
    return n;
}

// 计算在不超过N的正整数中满足g(n, k) = m的数的个数
int countUnreportableNumbers(int N, int k, int m) {
    int count = 0;
    for (int n = 1; n <= N; ++n) {
        if (g(n, k) == m) {
            ++count;
        }
    }
    return count;
}

int main() {
    int T;
    cin >> T;
    vector<int> results(T);

    for (int i = 0; i < T; ++i) {
        int N, k, m;
        cin >> N >> k >> m;
        results[i] = countUnreportableNumbers(N, k, m);
    }

    for (const auto& result : results) {
        cout << result % MOD << endl;
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3500kb

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

score: -100
Time Limit Exceeded

input:

5
114 1 5
514 2 10
114514 3 7
1919810 2 13
1145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810 1 79

output:


result: