Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
1.19/5 (6 votes)
See more:
There is a Grasshopper in a tropical forest. The grasshopper can jump only vertically and horizontally, and the length of jump is always equal to x centimeter. A GRasshopper has found herself at the center of some cell of the chess board of the size pxq centimeters(each cell is 1x1 centimeters). She can jump as she wishes for an arbitrary number of times, she can even visit a cell more than once. the only restriction is that she cannot jump out of the board.

The grasshopper can count the number of cells that she can reach from the starting position(x,y). Let's denote this amount by dx,y. your task is to find the number of such starting position(x,y), which have the maximum possible value of dx,y

Input

The integer array contains three integers p,q,x

p= length of the board
q= width of the board

x=length of the grasshoppers jump.

Output

Output the only integer - the number of the required starting position of the GRasshopper

Example

input 2 3 1000000
output 6

input 3 3 2
output 4
Posted
Comments
Ravi Bhavnani 5-Mar-14 14:08pm    
You seem to have mistaken this forum as a means to have someone do your homework for you. If you have a specific question ask it, but don't expect anyone to give you a solution to your assignment.

/ravi
S Houghtelin 5-Mar-14 14:35pm    
I think the solution is 42.
joshrduncan2012 5-Mar-14 15:34pm    
So what's your question?
ZurdoDev 5-Mar-14 17:05pm    
Perhaps there is a question somewhere?
Neo new to aps.net 7-Mar-14 11:41am    
It is difficult to understand the question

Can you suggest algorithm or steps to resolve this problem statement...

1 solution

C#
public static int squareCount(int[] input1)
        {
            int return_result;
            if (((input1[0] - 0.5) >= input1[2]) && ((input1[1] - 0.5) >= input1[2]))
            {
                return_result = 4;
            }
            else if ((((input1[0] - 0.5) >= input1[2]) && ((input1[1] - 0.5) < input1[2])) || (((input1[0] - 0.5) < input1[2]) && ((input1[1] - 0.5) >= input1[2])))
            {
                return_result = 2;
            }
            else
            {
                return_result = input1[0] * input1[1];
            }
            return return_result;
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900