Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Hints: Divisibility by 2^n

Any number can be written as

num = 2^x * remain

What happens to the product? What is the criteria for divisibility by 2^n?

Suppose the exponent of 2 in the resulting product is x. Then, you need

want = max(0, n - x)

Which index gives you the maximum benefit?

Compute the exponent of 2 for each index, sort them in descending order and greedily keep taking the largest exponent till you reach your goal.