結果

問題 No.639 An Ordinary Sequence
ユーザー ama_nukoama_nuko
提出日時 2018-11-27 03:38:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 1,000 ms
コード長 925 bytes
コンパイル時間 961 ms
コンパイル使用メモリ 97,084 KB
実行使用メモリ 18,992 KB
最終ジャッジ日時 2023-08-30 13:06:12
合計ジャッジ時間 2,144 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
18,880 KB
testcase_01 AC 17 ms
18,736 KB
testcase_02 AC 9 ms
18,672 KB
testcase_03 AC 9 ms
18,800 KB
testcase_04 AC 10 ms
18,992 KB
testcase_05 AC 9 ms
18,692 KB
testcase_06 AC 9 ms
18,804 KB
testcase_07 AC 9 ms
18,880 KB
testcase_08 AC 10 ms
18,536 KB
testcase_09 AC 9 ms
18,508 KB
testcase_10 AC 9 ms
18,860 KB
testcase_11 AC 9 ms
18,688 KB
testcase_12 AC 9 ms
18,796 KB
testcase_13 AC 10 ms
18,692 KB
testcase_14 AC 10 ms
18,816 KB
testcase_15 AC 12 ms
18,832 KB
testcase_16 AC 18 ms
18,800 KB
testcase_17 AC 9 ms
18,672 KB
testcase_18 AC 17 ms
18,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

vector<int> dp(1e6);

int f(int x){
    if(x < 1e6){
        return dp[x];
    }

    return f(x / 3) + f(x / 5);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    dp = vector<int>(1e6);
    dp[0] = 1;
    for(int i = 1; i < 1e6; i++){
        dp[i] = dp[i/3] + dp[i/5];
    }
    cout << f(n) << endl;

    return 0;
}
0