PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: raysh_07
Tester: apoorv_me
Editorialist: iceknight1093
DIFFICULTY:
TBD
PREREQUISITES:
None
PROBLEM:
You and K friends eat at a restaurant, with the total cost being N.
This is divided equally among the group, and everyone pays you back; however, if they owe you x they pay you x rounded down to the nearest integer instead.
What’s your total expenditure?
EXPLANATION:
Note that the description of what your friends pay, i.e rounding down to the nearest integer, is exactly the floor function.
For a real number x, this will be denoted \left\lfloor x \right\rfloor.
Including you, the group has K+1 people.
So, splitting the cost equally among everyone, each person owes Rs. \frac{N}{K+1}
Of this, you pay N, then your K friends each pay you back Rs. \left\lfloor \frac{N}{K+1} \right\rfloor.
So, your total expenditure is exactly
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (Python)
for _ in range(int(input())):
n, k = map(int, input().split())
print(n - k*(n//(k+1)))