Array ( [0] => [1] => questions [2] => Basic [3] => Dole-Out-Cadbury ) Codevita Previous Questions | Dole Out Cadbury | THE INQUISITIVE





Dole Out Cadbury

LEVEL:Beginner

Description

You are a teacher in reputed school. During Celebration Day you were assigned a task to distribute Cadbury such that maximum children get the chocolate. You have a box full of Cadbury with different width and height. You can only distribute largest square shape Cadbury. So if you have a Cadbury of length 10 and width 5, then you need to break Cadbury in 5X5 square and distribute to first child and then remaining 5X5 to next in queue

Input Format

First line contains an integer P that denotes minimum length of Cadbury in the box
Second line contains an integer Q that denotes maximum length of Cadbury in the box
Third line contains an integer R that denotes minimum width of Cadbury in the box
Fourth line contains an integer S that denotes maximum width of Cadbury in the box

Output Format

Print total number of children who will get chocolate.


Example 1:

Input
5 7 3 4
Output
24
Example 2:

Input
10 20 30 40
Output
1094
Example 3:

Input
1 2 3 4
Output
12

oops

Login to see Discussion




Approach

Step-i) create a method cadburry which takes min_lenght, max_length, min_width and max widtth as argument
Step-ii)intiaize count to 0
Step-iii)for i in range min_length to max_length
Step-iv)now in that loop for i in range min_width to max_width
Step-v)assign i to x and j to y
Step-vi)while x and y are greater than 1 if x is greater than y increment count and remove y from x else remove x from y and increment count
Step-vii)outside while if x and y equal to 1 add 1 to count
Step-viii)if y equal to 1 and x not then add x to count else add y to count
Step-ix)exit two loops and return count
Step-x)in main method take the necessary inputs and print the result


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution