- All Contests
- ProjectEuler+
- Project Euler #169: Exploring the number of different ways a number can be expressed as a sum of powers of 2.
- Discussions

# Project Euler #169: Exploring the number of different ways a number can be expressed as a sum of powers of 2.

# Project Euler #169: Exploring the number of different ways a number can be expressed as a sum of powers of 2.

kalok87 + 0 comments My math sucks but I still figure out how to do this. Search Stern's Diatomics Series and try to understand it. For those friends who have timeout problem in python, try to build up a dictionary and extend it as far as you can(remember dic[2**N] = 1 for diatomic series) and add few more other elements like dic[3] = 2 or dic[5] = 3. Recursively use the function and remember to update your dic everytime(important, otherwise timeout). You should see that you program solve all cases in seconds.

vishnuamritpydah + 0 comments How would you do this in a language like C++, where there is no simple way to store an integer value of 10^27? Please advise.

sandeepsmishra + 0 comments I was wondering should the

fn(10) be 12 like below

I dont understand what I am doing wrong here

jigneshk5 + 0 comments Can be solved more efficiently by dynamic programming. https://www.geeksforgeeks.org/perfect-sum-problem-print-subsets-given-sum/

likhithav22 + 0 comments public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */

`Scanner s = new Scanner(System.in); int n=s.nextInt(); int l=0,x=0; ArrayList<Integer> al = new ArrayList(); while(x<n){ x = 1 << l; al.add(x); } int[] count = new int[n+1]; count[0]=1; for(int i=1;i<n+1;i++){ for(int j=0;j<al.size();j++){ if(i>=al.get(j)) count[i]+=count[i-al.get(j)]; } } int k=count[n]; System.out.println(k); }`

what is the problem..showing:unsafe operations

Sort 28 Discussions, By:

Please Login in order to post a comment