Problem Link :
Difficulty : Easy-Medium
On the occasion of Children’s Day, you were invited as a guest in a school. During celebration you were asked to distribute chocolates among children such that maximum children can get the chocolate. You have a box full of chocolates with different width & height. You can only distribute largest shape chocolate. So if you have chocolate of length 10 and width 5, then you need to break it in 5x5 square and distribute to 1st child and then remaining 5x5 to next in queue.
0 <= T <= 1500
0 <= A,B <= 1500
0 <= C,D <= 1500
1) First line contains an integer T that denotes Number of Testcases
--> Following T testcases follow the below 4 points.
2) Second line contains an integer A that denotes minimum length of Chocolate in the box.
3) Third line contains an integer B that denotes maximum length of Chocolate in the box.
4) Fourth line contains an integer C that denotes minimum width of Chocolate in the box.
5) Fifth line contains an integer D that denotes maximum width of Chocolate in the box.
Print total number of children who will get the chocolate.
int no_of_children(int row, int col)
int count = 0;
int total = row * col;
while (row && col)
if (row > col)
row = row - col;
col = col - row;
int sum = 0;
int minlen, maxlen, minwid, maxwid;
scanf("%d%d%d%d", &minlen, &maxlen, &minwid, &maxwid);
if (0 < minlen < 1500 && 0 < maxlen < 1500 && 0 < minwid < 1500 && 0 < maxwid < 1500)
for (int i = minlen; i <= maxlen; i++)
for (int j = minwid; j <= maxwid; j++)
sum = sum + no_of_children(i, j);