TV - Editorial

PROBLEM LINK:

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

Author: raysh07
Tester: tabr
Editorialist: iceknight1093

DIFFICULTY:

TBD

PREREQUISITES:

None

PROBLEM:

A TV has X channels, of which the even-numbered ones stopped working.
How many channels are still working?

EXPLANATION:

The working channels are 1, 3, 5, \ldots — all the odd numbers upto X.

Since X is small, it is possible to count all such odd numbers by writing a loop.
Alternately, it can be seen that:

  • If X is even, exactly half the channels will remain. So, the answer is \frac{X}{2}.
  • If X is odd, a bit more than half the channels will remain: \frac{X+1}{2}.

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (Python)
x = int(input())
if x%2 == 0: print(x//2)
else: print(x//2 + 1)