Childrens Day - SSEC0029

Problem Link :
SSEC0029
Difficulty : Easy-Medium
Problem:
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.



Contraint:
0 <= T <= 1500
0 <= A,B <= 1500
0 <= C,D <= 1500

Input Format:
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.

Output Format:
Print total number of children who will get the chocolate.

Example Input:
1
5
7
3
4

Output Format:
24
Solution:
#include <bits/stdc++>

int no_of_children(int row, int col)
{
int count = 0;
int total = row * col;
while (row && col)
{
count++;
if (row > col)
row = row - col;
else
col = col - row;
}
return count;
}

int main()
{
int sum = 0;
int minlen, maxlen, minwid, maxwid;
int t;
scanf("%d", &t);
while (t–)
{
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);
}
}
}
printf("%d\n", sum);
}

return 0;

}