PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: notsoloud
Tester & Editorialist: iceknight1093
DIFFICULTY:
568
PREREQUISITES:
None
PROBLEM:
Chef purchased N items, each with a cost of X.
A valid phone number is a 5-digit number that has no leading zeros.
Is Chef’s total spending equivalent to a valid phone number?
EXPLANATION:
Buying N items for X each, Chef spent N\cdot X in total; so all that needs to be done is to check whether N\cdot X is a 5-digit number.
This can be done is various ways, for example:
- Convert N\cdot X to a string and check if its length equals 5.
For example, you can usestd::to_string
in C++ orstr
in Python; or - Use a
while
loop to count the number of digits in N\cdot X, and check if it equals 5; or - Check if 10000 \leq X \leq 99999.
TIME COMPLEXITY
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (Python)
for _ in range(int(input())):
n, x = map(int, input().split())
tot = n*x
print('Yes' if len(str(tot)) == 5 else 'No')