coder
Two friends communicate with cyclic coordinated numbers which they exchange with sms messages. The coding is done in the following way. If we need to code the number N, then all numbers from 1 to N are written in a circle, and every second number is deleted out of the circle until we have just one number left, which is the result of our coding.
If the message being coded is a question, then the coding begins with the number 1 (1 is the first number that is deleted from the circle), and if the message is an answer than the coding begins with the number 2.
Your program is supposed to solve this problem for the two friends by coding a large number ( up to 100 digits long).
The first and only line of the standard input contains the number N which you need to code, and the criteria for coding 1 or 2 (1=question, 2=answer).
The first and only line of the standard output should contain the result of the coding of the number N in the criteria of coding. It has to be written without the leading zeroes.
Input:
10 1Output:
4Explanation for the test case:
10 2Output:
5Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.