提出 #73048730


ソースコード 拡げる

#include <iostream>
using namespace std;

// Function to calculate the digit sum of a number
int calculateDigitSum(int num) {
    int sum = 0;
    while (num > 0) {
        sum += num % 10;  // Add the last digit to sum
        num /= 10;        // Remove the last digit
    }
    return sum;
}

int main() {
    int N, K;
    cin >> N >> K;
    
    int count = 0;
    // Iterate through all positive integers from 1 to N
    for (int i = 1; i <= N; ++i) {
        if (calculateDigitSum(i) == K) {
            count++;
        }
    }
    
    cout << count << endl;
    return 0;
}

提出情報

提出日時
問題 B - Digit Sum
ユーザ stone_shadow
言語 C++23 (GCC 15.2.0)
得点 200
コード長 610 Byte
結果 AC
実行時間 2 ms
メモリ 3620 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 200 / 200
結果
AC × 3
AC × 12
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 2 ms 3420 KiB
random_02.txt AC 1 ms 3620 KiB
random_03.txt AC 1 ms 3320 KiB
random_04.txt AC 1 ms 3420 KiB
random_05.txt AC 1 ms 3420 KiB
random_06.txt AC 1 ms 3312 KiB
random_07.txt AC 1 ms 3552 KiB
random_08.txt AC 1 ms 3544 KiB
random_09.txt AC 1 ms 3360 KiB
sample_01.txt AC 1 ms 3544 KiB
sample_02.txt AC 1 ms 3416 KiB
sample_03.txt AC 1 ms 3312 KiB