PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: raysh07
Tester: sushil2006
Editorialist: iceknight1093
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
A series has N episodes, each being K minutes long.
How much time, in hours and minutes, does it take to watch them all?
EXPLANATION:
N episodes and K minutes makes for a total of N\times K minutes worth of time.
We then need to convert N\times K to the (hour, minute) format.
There are a couple of ways of doing this:
- The brute-force approach.
Start with H = 0 and M = N\times K.
Then, as long as M \ge 60, subtract 60 from M and add 1 to H, essentially repeatedly converting 60 minutes into one hour.
In the end, the answer is the final values of H and M. - The math approach.
This is the same as the previous one, but with the additional observation that the repeated subtraction can be emulated by division.
That is, H will just equal the quotient when (N\times K) is divided by 60, while M will equal the remainder of the division.
So, you can directly print said quotient and remainder.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (PyPy3)
for _ in range(int(input())):
n, k = map(int, input().split())
mins = n*k
print(mins//60, mins%60)