結果

問題 No.639 An Ordinary Sequence
ユーザー merom686merom686
提出日時 2018-01-26 22:42:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 1,000 ms
コード長 459 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 76,812 KB
実行使用メモリ 7,228 KB
最終ジャッジ日時 2023-08-30 12:47:56
合計ジャッジ時間 1,611 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
7,192 KB
testcase_01 AC 11 ms
7,136 KB
testcase_02 AC 5 ms
7,016 KB
testcase_03 AC 5 ms
6,968 KB
testcase_04 AC 5 ms
6,972 KB
testcase_05 AC 5 ms
7,192 KB
testcase_06 AC 5 ms
6,916 KB
testcase_07 AC 5 ms
7,152 KB
testcase_08 AC 5 ms
6,912 KB
testcase_09 AC 4 ms
7,088 KB
testcase_10 AC 5 ms
6,960 KB
testcase_11 AC 4 ms
7,132 KB
testcase_12 AC 5 ms
6,912 KB
testcase_13 AC 5 ms
6,908 KB
testcase_14 AC 5 ms
7,228 KB
testcase_15 AC 7 ms
7,132 KB
testcase_16 AC 12 ms
6,968 KB
testcase_17 AC 5 ms
6,908 KB
testcase_18 AC 11 ms
7,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int m = 1 << 20;
vector<int> p(m);

int64_t dfs(int64_t i) {
    if (i < m) return p[i];
    return dfs(i / 3) + dfs(i / 5);
}

int main() {
    int64_t n;
    cin >> n;

    p[0] = 1;
    for (int i = 1; i < m; i++) {
        p[i] = p[i / 3] + p[i / 5];
    }

    cout << dfs(n) << endl;

    return 0;
}
0