結果

問題 No.639 An Ordinary Sequence
ユーザー stderrstderr
提出日時 2018-01-27 14:17:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 1,000 ms
コード長 621 bytes
コンパイル時間 742 ms
コンパイル使用メモリ 61,140 KB
実行使用メモリ 11,448 KB
最終ジャッジ日時 2023-08-30 12:53:06
合計ジャッジ時間 1,717 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
11,152 KB
testcase_01 AC 22 ms
11,316 KB
testcase_02 AC 7 ms
11,148 KB
testcase_03 AC 7 ms
11,152 KB
testcase_04 AC 6 ms
11,160 KB
testcase_05 AC 7 ms
11,196 KB
testcase_06 AC 7 ms
11,148 KB
testcase_07 AC 7 ms
11,192 KB
testcase_08 AC 7 ms
11,448 KB
testcase_09 AC 7 ms
11,148 KB
testcase_10 AC 7 ms
11,252 KB
testcase_11 AC 7 ms
11,148 KB
testcase_12 AC 7 ms
11,216 KB
testcase_13 AC 7 ms
11,256 KB
testcase_14 AC 8 ms
11,128 KB
testcase_15 AC 11 ms
11,192 KB
testcase_16 AC 22 ms
11,200 KB
testcase_17 AC 6 ms
11,252 KB
testcase_18 AC 22 ms
11,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
#define ll long long
using namespace std;

ll N;
static const int k = 1000000;
ll dp[k + 1] = {};

void init() {
  dp[0] = 1;
  rep1(i, k) {
    dp[i] = dp[i / 3] + dp[i / 5];
  }
}

ll a(ll n) {
  if (dp[0] == 0) init();
  if (n <= k) return dp[n];
  else return a(n / 3) + a(n / 5);
}

int main() {
  cin >> N;
  cout << a(N) << endl;
  return 0;
}
0