PRIMEDICE - Editorial

PROBLEM LINK:

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

Author: Amaan Parvez
Testers: Takuki Kurokawa, Utkarsh Gupta
Editorialist: Nishank Suresh

DIFFICULTY:

643

PREREQUISITES:

None

PROBLEM:

Alice rolls a die and gets A, while Bob gets B. Is their sum a prime?

EXPLANATION:

The numbers rolled are between 1 and 6, so the sum can only be an integer between 2 and 12.

In this range, the prime numbers are 2, 3, 5, 7, 11. So, check if A+B is one of these prime numbers or not — the output is Alice if it is, Bob if it isn’t.

TIME COMPLEXITY

\mathcal{O}(1) per test case.

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
    a, b = map(int, input().split())
    print('Alice' if a+b in [2, 3, 5, 7, 11] else 'Bob')