1 Like

**who can make (m+1) first will win the game**

1 Like

**now (m+1) is possible only if the remainder is in the range (1 to m)**

1 Like

**n=6 , m=4 now 6%5=1 so A will select 1 and make the number 6-1=5 so A wins**

1 Like

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)

1 Like

I am so much glad that you understand the problem and able to solve it.

1 Like

Refer these notes for this problem

3 Likes

By searching online

2 Likes

@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
```

Please help.

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

2 Likes