Nim Take Stones

EasyMathGame Theory

Description

Two players play optimally. A pile has n stones. On each turn a player removes between 1 and k stones inclusive. The player who removes the last stone wins. Return true if the first player wins.

Examples

Input:n = 4, k = 3
Output:false
Explanation:

Whatever first player takes, second can take to leave a multiple of 4 again, eventually forcing first to lose.

Input:n = 5, k = 3
Output:true
Explanation:

First takes 1 to leave 4, then mirrors.

Input:n = 1, k = 1
Output:true
Explanation:

First player takes the only stone.

Constraints

  • 1 ≤ n ≤ 10⁹
  • 1 ≤ k ≤ 100

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.