CE20201C Editorial

PROBLEM LINK:

contest : https://www.codechef.com/CE12020/problems/CE20201C
Practice: https://www.codechef.com/problems/CE20201C

Author: shanvid
Tester: shanvid
Editorialist: shanvid

DIFFICULTY:

Easy

PREREQUISITES:

Basic Maths

PROBLEM:

A few even number of friends decided to play a game on a merry Go Round. At the start the ball is with player 0. The player throws the ball to the opposite player. Now ever player with the ball throws the ball to the opposite player. Now this game is played with the merry go round spinning. Now as the merry go round spins, when the ball is thrown, instead of ball being received by opposite player, but dur to the spin the ball is received by a adjacent player opposite to the spin direction. After N such iteration where in ever iteration, a ball is thrown once, find which player will receive the ball.

Players are named player0, player1 to player(N-1). There are N number of players and N seats and no seats are empty. There are in total K iterations. The merry go round may spin clockwise or anti-clockwise.

EXPLANATION:

Input:

  • First line contains Nnumberofplayers−SecondlinecontainsNnumberofplayers−SecondlinecontainsK number of throws/iterations
  • Third line contains spin direction[0forclockwise,0forclockwise,1 for anticlockwise]

Output:

Output is a integer value showing the player number who has the ball.

Constraints

  • 1≤N≤1091≤N≤109
  • 1≤K≤1091≤K≤109
  • spin = 1 || 0

Sample Input:

8
1
1

Sample Output:

5

EXPLANATION:

Player0 throws the ball opposite to player 4 but due to spin player 5 [as spin is anti clockwise] receivers it

SOLUTIONS:

n = int(input())
k = int(input())
s = int(input())
a=0
pos = 0
if s == 0:
for i in range(0,k):
pos = ((n/2)-1+pos)%n
else:
for i in range(0,k):
pos = ((n/2)+1+pos)%n
print(int(pos))