Author: | A. Verkholat | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
Vasya wrote down all the numbers from 1 to N in a row.
He performs the following algorithm until there are no more numbers.
1) Discards the number from the beginning of the list.
2) Discards the number from the end of the list.
3) Reverses the order of the remaining numbers.
4) Goes to the first instruction.
What number will Vasya discard on the K-th step?
First line contains 2 integers: N and K.
A single integer representing K-th discarded number.
1 ≤ N ≤ 109
1 ≤ K ≤ N
Initial list: 1 2 3 4 5 6 7 8 9 10.
Vasya discards the first number: 2 3 4 5 6 7 8 9 10.
Discards from the end: 2 3 4 5 6 7 8 9.
Reverses the list: 9 8 7 6 5 4 3 2.
Discards the first number: 8 7 6 5 4 3 2.
Discards from the end: 8 7 6 5 4 3.
Reverses the list: 3 4 5 6 7 8.
The fifth discarded number was 3, which is the answer.
No. | Standard input | Standard output |
---|---|---|
1 |
|
|