Split the Bill

Medium · rating 1150 · Math

A restaurant bill of total cents is split evenly among n people. So no one underpays, each person's share is rounded up to a whole cent. Read two space-separated integers total n and print the amount each person pays.

Constraints: 0 ≤ total ≤ 109, 1 ≤ n ≤ 105

Editorial

Approach

Splitting evenly with rounding up is ceiling division. The integer-only trick is (total + n − 1) // n, which rounds up without ever touching floating point.

total, n = map(int, input().split())
print((total + n - 1) // n)

Why not floats

ceil(total / n) with floating point can round incorrectly for large values; the integer form is exact.

Complexity

Time: O(1). Space: O(1).

Related problems

Open Split the Bill in Code Arena →