The taking away k/p marble game

214 Views Asked by At

Came up with this game, haven't thought of a catchy name for it, but here it goes:

There are $n$ marbles. Two players alternate between taking away $\frac{kn}{p}$ marbles, where $p$ is a prime number (prime divisor of $n$) and $1 \le k < p < n$ ($n$ is the current number of marbles). The players get to choose $p$ and $k$ for each turn.
The first player who can't complete their turn (i.e. when you can't take away a natural number of marbles which can be written as $kn/p$) loses.

For example, let $n = 30$. The starting player can take away $30*2/5 = 12$ marbles, which results in $18$ marbles. No matter what the second player does (take away $18*1/3$, $18*2/3$ or $18*1/2$), they result in winning states for the starting player ($6$, $9$ or $12$). So $n=30$ is a winning state.

The premise is simple, yet I have difficulties with finding a general formula to decide if a game state is winning or losing. I've tried constraining $p$, and managed to find a pattern which was easily provable, but I haven't been able to work it out for all possible $p$.
Other than the obvious (prime numbers are losing states, etc.) I have no clue. I wrote a simple python script to try out all combinations, but that didn't help either.
Any ideas?

1

There are 1 best solutions below

2
On

Update: I just realized that the solution below ignores your condition $p\lt n$. Due to this constraint, a prime factor can no longer be picked if it’s the only one left. That destroys the independence of the prime factors; they can no longer be considered as piles where you can play independently and whose nim-values can therefore be XORed. I’ll nevertheless try to finish the proof below for the modified (and much simpler) game.


I’ll assume that you know about nim-values (if not, you should read up on them).

Write $n=sp$, with $s\in\mathbb N$. Then taking $\frac{kn}p$ marbles leaves $n-\frac{kn}p=sp-\frac{ksp}p=s(p-k)$ marbles. So what you do in each turn is pick a prime factor and reduce it, leaving all other prime factors unchanged. If you view the prime factors as piles as in the game of Nim, a move consists of reducing one of the piles (leaving at least one object) and then replacing it by piles corresponding to its prime factors.

Thus, the nim-value of a number is the XOR of the nim-values of its prime factors, and all you need for perfect play are the nim-values of the primes. I believe the nim-value of $p_n$ is $n$; I’ll try to post a proof for that shortly.