There are N children and Chef wants to give them 1 candy each. Chef already has X candies with him. He can buy packets containing exactly 4 candies each.
We have to determine the minimum number of candy packets Chef must buy so that he is able to give 1 candy to each of the N children.
Chef already has X candies with him.
Ideally, he needs (N - X) new candies.
Since he can only buy in packets of 4, he will end up buying (N-X)/4 packets rounded up to the nearest integer.
One caveat here is that if N \leq X, then the Chef doesn’t need to buy anything.
Time complexity is O(1).
import math t=int(input()) for _ in range(t): N,X=map(int,input().split()) print(math.ceil((max((N-X),0)/4)))