RURT - Editorial

PROBLEM LINK:

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

Author: pols_agyi_pols
Tester: mexomerf
Editorialist: iceknight1093

DIFFICULTY:

TBD

PREREQUISITES:

None

PROBLEM:

Chef is participating in a race that’s Y kilometers long, but needs to take a break every X kilometers.
How many times will he take a break before finishing the race?

EXPLANATION:

Chef will take breaks after running X, 2X, 3X, \ldots kilometers.
So, the answer is the largest integer k such that kX \lt Y (note that if kX = Y then Chef would’ve finished the race and so won’t need a break).

Since X and Y are small, you can find k by just looping over it starting from 0.
Alternately, the answer can be mathematically expressed as

\left\lfloor \frac{Y-1}{X} \right\rfloor

where \left\lfloor z \right\rfloor represents the result of rounding z down to the nearest integer, i.e., the largest integer that’s \leq z.

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (PyPy3)
x, y = map(int, input().split())
print((y-1)//x)