Candies
2025, Dec 15
Problem: Chef wants to give 1 candy to each of $N$ children. He currently has $X$ candies. He can buy packets containing 4 candies each. Find the minimum number of packets he needs to buy.
Logic:
Example: $N=20, X=12$
Example: $N=10, X=5$
READ T
FOR i FROM 1 TO T:
READ N, X
IF X >= N:
PRINT 0
ELSE:
needed = N - X
# Ceiling division (needed / 4)
packets = (needed + 3) / 4 (integer division)
PRINT packets
A: 0, because Chef already has enough candies ($X$) to give one to every child ($N$). No packets needed.