2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

An Ordinary Sequence

Posted at

問題

解法

  • 単純にメモ化再帰だけで良いです。これは、n/x/y == n/y/x (== n/(x*y)) がどのような自然数に対しても成立するため、当然 n/3/5 == n/5/3 となるからです。
  • 証明は https://qiita.com/cielavenir/items/21a6711afd6be8c18c55 をご覧ください。

答案

$memo={0=>1}
def dfs(n)
	$memo[n]||=dfs(n/3)+dfs(n/5)
end
p dfs(gets.to_i)
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?