Pile Game

 

Mahirl is a little girl who loves to play. Today she is playing by moving some stones between two piles of stones. Initially, one of the piles has A and the other has B stones in it.

Mahirl has decided to perform a sequence of K operations. In each operation she will double the size of the currently smaller pile. Formally, if the current pile sizes are labeled X and Y in such a way that X <= Y, she will move X stones from the second pile to the first one. After this move the new pile sizes will be X+X and Y-X.

Given the ints AB, and write a program to determine the size of the smallest pile after Mahirl finishes all her operations.
 

Input and Output Format:

Input consists of 3 integers – A, B and K .

The first integer corresponds to A, the number of stones in the first pile.

The second integer corresponds to B, the number of stones in the second pile.

The third integer corresponds to K, the number of operations performed.
 

Output consists of an integer that corresponds to the size of the smallest pile.

 

Sample Input :

4

7

2

 

Sample Output :

5

1

t7

1
1
2000

0

2

t3

2
6
1

4

3

t2

5
5
3

0

4

t4

2
8
1

4

5

t10

231
5
10

72

 

No comments:

Post a Comment