Find Remainder
Practice this coding question on Coding Gurukul.
Problem statement
A stationery store packs pencils into boxes of a fixed capacity. After filling as many complete boxes as possible, some pencils may remain loose. The store receives several independent packing requests, each with its own pencil count and box capacity. Your program calculates the loose remainder for each request so staff can label the unfinished boxes correctly. Your task For every test case, read n and m. Divide n items into complete groups of m and output the number left over. The answer is the nonnegative remainder n modulo m. The box capacity is positive, and no pencil can be split. Important details If n is smaller than m, no full box can be filled and all n pencils remain. If n is a multiple of m, the remainder is zero. Do not output the quotient or the number of boxes. Worked example Packing 17 pencils into boxes holding 5 fills three boxes and leaves 2 pencils. Therefore that request produces 2.
Input format
First line: T. Next T lines: n m.
Output format
Print n modulo m for each test case.
Constraints
1 <= T <= 1000; 0 <= n <= 1000000000; 1 <= m <= 1000000000.
Sample input
2 17 5 4 9
Sample output
2 4
Sign in to run or submit a solution in C++, Java or Python.