PZSPLIT - Editorial

PROBLEM LINK:

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

Author: iceknight1093
Tester: sushil2006
Editorialist: iceknight1093

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

One pizza has N slices. How many pizzas do Chef and Chefina need to buy, to ensure that they can eat an equal number of slices?

EXPLANATION:

If N is even, buying one pizza is enough: Chef and Chefina can eat \frac{N}{2} slices each.

If N is odd, buying one pizza will not be enough: there’s no way to split an odd number of slices equally between two people.
So, at least two pizzas need to be bought.
Two pizzas is, of course, enough: Chef can eat N slices and Chefina can eat N slices.

So,

  • If N is even, the answer is 1.
  • If N is odd, the answer is 2.

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (PyPy3)
n = int(input())
print(1 if n%2 == 0 else 2)