Dangling else problem

Martha is interviewing at Subway. One of the rounds of the interview requires her to cut a bread of size into smaller identical pieces such that each piece is a square having maximum possible side length with no left over piece of bread.
Input Format
The first line contains an integer . lines follow. Each line contains two space separated integers and which denote length and breadth of the bread.
Constraints
Output Format
lines, each containing an integer that denotes the number of squares of maximum size, when the bread is cut as per the given condition.
Sample Input 0
2
2 2
6 9
Sample Output 0
1
6
Explanation 0
The 1st testcase has a bread whose original dimensions are , the bread is uncut and is a square. Hence the answer is 1.
The 2nd testcase has a bread of size . We can cut it into 54 squares of size , 6 of size . For other sizes we will have leftovers. Hence, the number of squares of maximum size that can be cut is 6.
My solution for this question in C:
Animesh has empty candy jars, numbered from to , with infinite capacity. He performs operations. Each operation is described by integers, , , and . Here, and are indices of the jars, and is the number of candies to be added inside each jar whose index lies between and (both inclusive). Can you tell the average number of candies after operations?
Input Format
The first line contains two integers, and , separated by a single space.
lines follow; each of them contains three integers, , , and , separated by spaces.
Constraints
Output Format
A single line containing the average number of candies across jars, rounded down to the nearest integer.
Note: Rounded down means finding the greatest integer which is less than or equal to the given number. E.g. 13.65 and 13.23 are rounded down to 13, while 12.98 is rounded down to 12.
Sample Input
5 3
1 2 100
2 5 100
3 4 100
Sample Output
160
My
Comments
Post a Comment