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

  • + 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