Coding Competitions

Q1. There is a Grasshopper in a tropical forest. The grasshopper can jump only vertically and horizontally, and the length of the jump is always equal to x centimeters. A grasshopper has found itself at the center of some cell of the chess board of the size pxq centimeters(each cell is 1x1 cm). 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 amount of cells that she can reach from the starting position(x, y). Let's denote this amount by d(x,y). Your task is to find the number of such starting positions(x, y), which have the maximum possible value of d(x,y). [source: Techgig March 2014 competition]


Input:
The integer array contains 3 integers p, q, x (1 <= p, q, x <= 1000000)
p = length of the board
q = width of the board
x = length of the grasshopper's jump

Output:
Output the only integer - the number of the required starting positions of the grasshopper

Examples
input : 2 3 1000000
output: 6

input : 3 3 2
output: 4

No comments :

Post a Comment