結果

問題 No.639 An Ordinary Sequence
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-03-28 10:20:01
言語 Ruby
(3.3.0)
結果
AC  
実行時間 651 ms / 1,000 ms
コード長 295 bytes
コンパイル時間 616 ms
コンパイル使用メモリ 11,208 KB
実行使用メモリ 23,220 KB
最終ジャッジ日時 2023-08-30 13:03:28
合計ジャッジ時間 11,044 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 632 ms
22,948 KB
testcase_01 AC 649 ms
23,076 KB
testcase_02 AC 368 ms
23,220 KB
testcase_03 AC 366 ms
23,084 KB
testcase_04 AC 368 ms
23,152 KB
testcase_05 AC 370 ms
23,172 KB
testcase_06 AC 371 ms
23,156 KB
testcase_07 AC 369 ms
22,948 KB
testcase_08 AC 372 ms
22,996 KB
testcase_09 AC 371 ms
23,204 KB
testcase_10 AC 367 ms
22,988 KB
testcase_11 AC 367 ms
23,204 KB
testcase_12 AC 370 ms
23,144 KB
testcase_13 AC 376 ms
23,124 KB
testcase_14 AC 398 ms
22,992 KB
testcase_15 AC 453 ms
23,032 KB
testcase_16 AC 651 ms
23,052 KB
testcase_17 AC 369 ms
23,208 KB
testcase_18 AC 650 ms
22,980 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def f(n,memo)
	if memo[n]!=0
		return memo[n]
	end
	
	if n==0
		return 1
	else
		return f(n/3,memo)+f(n/5,memo)
	end
end

def g(memo,n)
	if n<=1000000
		return memo[n]
	else
		return g(memo,n/3)+g(memo,n/5)
	end
end

memo=[0]*1000001
1000001.times{|i|
	memo[i]=f(i,memo)
}
puts g(memo,gets.to_i)
0