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

前端 未结 3 1122
被撕碎了的回忆
被撕碎了的回忆 2021-02-11 04:07

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:31

    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

提交回复
热议问题