結果

問題 No.220 世界のなんとか2
ユーザー tamiflu__shrinetamiflu__shrine
提出日時 2015-06-22 19:01:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,015 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 59,480 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-21 23:42:52
合計ジャッジ時間 1,365 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    
    unsigned long long p;
    cin >> p;
    unsigned long long result1 = 0;
    unsigned long long result2 = 0;
    unsigned long long result3 = 0;
    
    // 3の倍数
    result1 = (unsigned long long)(powl(10, p) / 3);
    
    // 3の付く数
    unsigned long long init = 1;
    for (int i = 1; i <= p; i++) {
        
        if (i == 1) {
            result2 = init;
        } else {
            result2 = init * 9 + powl(10, i - 1);
            init    = result2;
        }
    }
    
    // 3の倍数かつ3の付く数
    init = 1;
    for (int i = 1; i <= p; i++) {
        
        if (i == 1) {
            result3 = init;
        } else {
            result3  = init * 3 + (init - 1) * 6 + (unsigned long long)(powl(10, i - 1) / 3) + 1;
            init     = result3;
        }
    }
    
    // 出力
    unsigned long long result = result1 + result2 - result3;
    printf("%llu\n", result);
    
    return 0;
}
0