FIZZBUZZ23_2 - Editorial

PROBLEM LINK:

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

Authors: naisheel, jalp1428
Tester: tabr
Editorialist: iceknight1093

DIFFICULTY:

716

PREREQUISITES:

None

PROBLEM:

There are N buns. A family of 5 needs X buns each daily, and can survive for D days after the buns run out.
Find the number of days they can survive for.

EXPLANATION:

There are 5 people, each needing X buns.
This is a total of 5X buns each day.

N buns will thus last for \displaystyle\left\lfloor \frac{N}{5X} \right\rfloor days, where \left\lfloor \ \right\rfloor denotes the floor function.

Adding in the extra D days, we see that the final answer is

\left\lfloor \frac{N}{5X} \right\rfloor + D

TIME COMPLEXITY

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
    n, x, d = map(int, input().split())
    print(n//(5*x) + d)