Number of ways to write n as a sum of powers of 2

前端 未结 3 1456
余生分开走
余生分开走 2021-02-11 03:45

Is there any algorithm to find out that how many ways are there for write a number for example n , with sum of power of 2 ?

example : for 4 there are four ways :

3条回答
  •  隐瞒了意图╮
    2021-02-11 04:33

    A recursive definition of the sequence (from Peter's link to A018819):

    f(n) = 1 if n = 0, Sum(j = 0..[n/2], f(j)) if n > 0 http://mathurl.com/nuaarfm.png

提交回复
热议问题