Acc to me once the loop for(int i=2 starts k should be initialized to the original value to count the correct value of occurances as 4 will have zero occurance as 2 will use all powers of 2 and that will not be able to count in i=4
Acc to me once the loop for(int i=2 starts k should be initialized to the original value to count the correct value of occurances as 4 will have zero occurance as 2 will use all powers of 2 and that will not be able to count in i=4