結果

問題 No.639 An Ordinary Sequence
ユーザー chocoruskchocorusk
提出日時 2018-09-20 09:48:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 1,000 ms
コード長 654 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 72,352 KB
実行使用メモリ 11,368 KB
最終ジャッジ日時 2023-08-30 13:01:00
合計ジャッジ時間 1,750 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

ll a[1000000];

ll solve1(ll n){
  if(a[n]>0) return a[n];
  return a[n]=solve1(n/3)+solve1(n/5);
}

ll solve(ll n){
  if(n<1000000) return a[n];
  return solve(n/3)+solve(n/5);
}

int main()
{
	ll n; cin>>n;
  a[0]=1;
  if(n<1000000){
    cout<<solve1(n)<<endl;
    return 0;
  }
  for(ll i=1; i<1000000; i++){
    solve1(i);
  }
  cout<<solve(n)<<endl;
	return 0;
}
0