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 :
4 = 4
4 = 2 + 2
4 = 1 + 1 + 1 + 1
4 = 2 + 1 + 1
thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Suppose g(m) is the number of ways to write m as a sum of powers of 2. We use f(m,k) to represent the number of ways to write m as a sum of powers of 2 with all the numbers’ power is less than or equal to k. Then we can reduce to the equation:
Take 6 as an example:
Here is the code below:
Hope it helps!