who can make (m+1) first will win the game
now (m+1) is possible only if the remainder is in the range (1 to m)
n=6 , m=4 now 6%5=1 so A will select 1 and make the number 6-1=5 so A wins
so divide the number with n%(m+1) so if the remainder comes in the range 1 to m then the particular guy can select that number and make (m+1)
I am so much glad that you understand the problem and able to solve it.
Refer these notes for this problem
@cubefreak777 Wow, that is impressive. btw how did you find it?
By searching online
@cubefreak777 Can you tell me what is wrong in my code?
import random t = int(input()) for i in range(t): a, b = map(int, input().split()) n =  k = 0 for _ in range(b): n.append(k+1) k = k + 1 m = 0 while True: ra = 0 + random.choice(n) if ra == a: break ai = m if ai % 2 == 0: print('A') else: print('B') else: if ra == 2: print('A') elif ra == 1: print('B') else: pass break m = m + 1
I got a TLE
Constraints are large and problem expects an O(1) solution and your code doesn’t looks like a constant time solution to me