BF21JC - Editorial

PROBLEM LINK:

[Practice ]( The Mysterious Island | CodeChef)

Setter- Aritra Banerjee
Tester- Rounak Das
Editorialist- CodeChef CIEM Chapter

DIFFICULTY:

CAKEWALK/SIMPLE

PROBLEM:

Let me denote knowledge by A and power by B. Now, as given in the question, we initially have A=1 and B=1. Tell if its possible for you to reach A=N and B=M using following operations-

  • Increase A by X
  • Increase B by Y
  • Increase A and B by 1. We can only do it once.

QUICK-EXPLANATION:

Key to AC- Modulo along with careful checking for corner case (N=1 or M=1) fetched AC in first try.

SOLUTION (in Python) :

t = input()
t = int(t)

for _ in range(t):
    n, m, x, y = input().split()
    n = int(n)
    m = int(m)
    x = int(x)
    y = int(y)
    n -= 1
    m -= 1
    flag = 0
    if n % x == 0 and m % y == 0:
        flag = 1
    n -= 1
    m -= 1
    if n >= 0 and m >= 0:
        if n % x == 0 and m % y == 0:
            flag = 1

    if flag == 1:
        print("Chefirnemo")
    else:
        print("Pofik")