Sie sind auf Seite 1von 3

Problem Set(08-Oct-2011)

Problem A: Circular Way

This Dasara we all N students gathered for Ravan-Dahan. After the celebration, we all sat in a circle for dinner and eagerly waited for the food to be served. The Sweet specially, however was served in an interesting way. Starting from anyone of the student the waiter served sweet leaving X students. Fortunately or unfortunately waiter started serving the sweet from Brijesh. And immediately Brijesh started wondering when will he be served the sweet again?? Can you please help him to crack this question??

, N-1 in clock-wise order . The

waiter starts from 0(Brijesh :P) and make jumps of X students at a time clock-wise to serve

Given a circle having N students numbered 0, 1, 2, 3, 4,

the sweet. After how many steps will the sweet reach Brijesh again.

Input

N and X is given as input

Output

Print the answer in a single line, followed by a '\n'

Constraint

2 <= N <= 10^18

1 <= X <= N

Time Limit : 1s

Sample case 1:

Input:

5 3

Output:

5\n

Explanation:

0 --> 3 --> 1 --> 4 --> 2 --> 0 = 5 steps

Sample case 2:

Input:

6 4

Output:

3\n

Explanation:

Problem B: Train Travel

There is a place named "Narnia". The only transportation available there is Railways. And the

stations are all numbered. And for one to go from any one station to another has to travel via all the intermediate numbered stations. i.e the only path from station N to station 1 is N,N-

1,N-2,

,3,2,1.

However, only three kind of trains run in "Narnia".

1. Which covers only 1 station i.e If train starts at Station Number 100 it will go at max to

Station Number 99 (100-1 = 99).

2. Which covers stations in multiple of 2 i.e If train starts at Station Number 80 it will go at

max to Station Number 40 (80/2 = 40).

3. Which covers stations in multiple 3 i.e If train starts at Station Number 21 it will go at max

to Station Number 7 (21/3 = 7).

"However, you can't get down at any Intermediate Station. You can only get down at the final station"

The train of type 1 is available at all the stations, that of type 2 is available at all even numbered stations and that of type 3 is available at stations whose number is divisible by 3.

Now say you are at Station Number X and you want to reach Station Number 1. What is minimum number of train changes you need to make to reach Station 1 from Station X

Input:

X is given as input

Output:

Print the answer in a single line, followed by a '\n' ( just print a new line, no need to display '\n' )

Constraints:

1 <= X <= 10 5 Time Limit : 1s

Sample Case 1:

Input:

6

Output:

2\n

Explanation:

6 / 3 = 2, 2 - 1 = 1 ; 2 steps

Problem C : Heritage Marathon

There is a Heritage Marathon in Hyderabad which starts from Charminar at 5.30AM sharp on 9th-Oct-2011 and ends at Golconda Fort. AK is going to take part in it but he lands in a problem. So he called Pankaj and ask the route by which he can get the maximum energy drinks on the way. Pankaj as usual Google's Marathon site( http://www.hyderabadheritagemarathon.com ) and founds a map of the route. The map is of Grid strucure(size N X N) and units of Energy Drink available at each square grid were seen on the map. Moreover Pankaj knew AK being lazy will move only right and down in map so Pankaj and other TAs being more lazy decided to ask you guys to help AK by solving this problem asap.

Formally Speaking:

Given a N x N grid, where each cell contains some units of Energy Drink. AK starts at cell (1,1) and wants to reach the cell (N,N). From a cell (i,j) he can either move one cell down or right, i.e., to cell (i+1,j) or (i,j+1). Find the maximum number of units of Energy Drinks he can collect along a path from (1,1) to (N,N).

Constraints:

 1 <= N <= 1000 0 <= units[i][j] < 100

Input:

N

(Following N lines will have N X N integer values)

Output:

Maximum_units(new line)

Time Limit : 1s

Sample Case:

Input:

 3 2 8 10 4 1 4 2 3 9

Output:

33\n

Explanation:

(1,1)--->(1,2)--->(1,3)--->(2,3)--->(3,3)

2

+

8

+

10

+

4

+

9

=

33