結果

問題 No.639 An Ordinary Sequence
ユーザー @abcde@abcde
提出日時 2019-05-19 18:14:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,721 bytes
コンパイル時間 2,986 ms
コンパイル使用メモリ 166,412 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 07:57:30
合計ジャッジ時間 6,937 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL a[101];

// 数列の項番を分解して, 元の数列の値を, 再帰的に計算.
// @param X: 数列の項番.
// @return ret: 数列の値.
LL recursive(LL X){
    
    // 1. 引数X を 3, 5 で割る.
    LL ret = 0;
    LL x3 = X / 3, x5 = X / 5;
    
    // 2. x3, x5 の 値が, 100以下となっていたら, 処理終了.
    if(x3 <= 100 && x5 <= 100) return (a[x3] + a[x5]);
    
    // 3. 2. 以外の場合は, 再帰処理.
    if(x3 <= 100 && x5 > 100){
        ret = a[x3] + recursive(x5);
        return ret;
    }
    if(x3 > 100 && x5 <= 100){
        ret = recursive(x3) + a[x5];
        return ret;
    }
    return (recursive(x3) + recursive(x5));

}

int main() {
    
    // 1. 入力情報取得.
    LL N;
    scanf("%llu", &N);
    
    // 2. 数列を設定.
    for(int i = 0; i < 101; i++){
        if(i == 0)              a[i] =  1;
        if(i >= 1 && i <= 2)    a[i] =  2;
        if(i >= 3 && i <= 4)    a[i] =  3;
        if(i >= 5 && i <= 8)    a[i] =  4;
        if(i >= 9 && i <= 14)   a[i] =  5;
        if(i >= 15 && i <= 24)  a[i] =  7;
        if(i >= 25 && i <= 26)  a[i] =  8;
        if(i >= 27 && i <= 44)  a[i] =  9;
        if(i >= 45 && i <= 74)  a[i] = 12;
        if(i >= 75 && i <= 80)  a[i] = 15;
        if(i >= 81 && i <= 100) a[i] = 16;
    }
    
    // 3. 数列を計算.
    LL ans = recursive(N);
    // for(int i = 1; i < 101; i++){
    //     LL t = recursive(i);
    //     cout << "i=" << i << " t="<< t << endl;
    // }
    
    // 4. 出力.
    // ex.
    // 1000000000000000000
    // -> 3207281389 で, 791[ms] かかった.
    printf("%llu\n", ans);
    return 0;
    
}
0