EXPENSES - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: notsoloud
Testers: IceKnight1093, tabr
Editorialist: IceKnight1093

DIFFICULTY:

719

PREREQUISITES:

None

PROBLEM:

Chef earns 2^X rupees a month, and has N expenses.
The i-th expense has a cost equal to half the amount Chef has remaining after paying the first i-1.
How much money does Chef have in the end?

EXPLANATION:

Each expense cuts Chef’s money in half.

There are N expenses, so Chef’s money is cut in half N times. In other words, it’s divided by 2^N.

Chef starts with 2^X, so his final money is \frac{2^X}{2^N} = 2^{X-N}

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
    n, x = map(int, input().split())
    print(2 ** (x - n))