Pass the Parcel

tanvirtareq SEC Inter University Juni...
Limits 1s, 512 MB

There are nn people in a room. They want to play a game called “pass the parcel”.

The people are numbered from 00 to n1n-1.

If ithi^{\text{th}} person has the parcel in ttht^{\text{th}} second, he gives it to the jthj^{\text{th}} person in (t+1)th(t+1)^{\text{th}} second.

where j={i+1; if 0in20; otherwise j = \left\{\begin{matrix} i+1 \text{; if } 0\le i \le n-2\\0 \text{; otherwise }\\\end{matrix}\right.

For example, At 0th0^{\text{th}} second, the 0th0^{\text{th}} person has the parcel. The next second (1st)1^{\text{st}}), he gives the parcel to the 1st1^{\text{st}} person. And the next second, he gives it to 2nd2^{\text{nd}} person and so on. And when the (n1)th(n-1)^{\text{th}} has the parcel he gives it to the 0th0^{\text{th}} person in next second. And again 0th0^{\text{th}} person gives it to 1st1^{\text{st}} person in next second. It will continue this way.

You will be given an integer kk. You have to answer who will have the parcel in the kthk^{\text{th}} second.


The first (and the only) input line contains two integers n(1n1000)n(1\le n \le 1000) and k(0k1000)k(0\le k\le 1000)— number of people, and time respectively.


Print the number of the person, who will have the parcel in the kthk^{\text{th}} second, in a single line.


2 2
3 5


Login to submit.


96% Solution Ratio
AlfehsaniEarliest, 5M ago
allmymistakesFastest, 0.0s
user.503209Lightest, 0 B
SabbasachiSutradharShortest, 39B
Toph uses cookies. By continuing you agree to our Cookie Policy.