Skip to main content
OlympiadHQ

Browse · MathNet

Print

Baltic Way 2023 Shortlist

Baltic Way 2023 counting and probability

Problem

Fifty marbles are lying in a heap. Alfred and Bodil take turns in removing a positive number of marbles, Alfred starts and at each step the number of marbles removed needs to be a prime or a square. The winner is the one who empties the heap. Who wins if both play in an optimal way?
Solution
We make a table inductively that shows whether the player, whose turn it is if there are marbles left, wins (marked with a W) or loses (marked with an L).
1
W
-1
2
W
-2
3
W
-3
4
W
-4
5
W
-5
6
L
7
W
-1
8
W
-2
9
W
-3
10
W
-4
11
W
-5
12
L
13
W
-1
14
W
-2
15
W
-3
16
W
-4
17
W
-5
18
L
19
W
-1
20
W
-2
21
W
-3
22
W
-4
23
W
-5
24
L
25
W
-1
26
W
-2
27
W
-3
28
W
-4
29
W
-5
30
L
31
W
-1
32
W
-2
33
W
-3
34
W
-4
35
W
-5
36
W
-36
37
W
-7
38
L
39
W
-1
40
W
-2
41
W
-3
42
W
-4
43
W
-5
44
L
45
W
-1
46
W
-2
47
W
-3
48
W
-4
49
W
-5
50
L
The proof of the correctness of the table is inductive. If there are at most 35 marbles left, a player cannot remove a number of marbles of the type with , because the numbers 6, 12, 18, 24 and 30 are neither prime numbers nor squares. We can conclude inductively that, as long as , the number should be marked with an L if it is divisible by 6 (since a legal move will yield a number that is not divisible by 6), and it should be marked with a W if it is not divisible by 6 (since removing 1, 2, 3, 4 or 5 marbles yields to a number that is divisible by 6).

This argument is not valid for , as one can remove all 36 marbles in one step and thus win.

The number is also winning, since one can remove 7 marbles to bring the opponent into a losing position with 30 marbles.

With marbles left it is not possible to win, since one would need to remove , , , , or all 38 marbles to bring the opponent into a losing position, but the numbers 8, 14, 20, 26, 32 and 38 are neither prime numbers nor squares.

The next five numbers, 39, ..., 43 are winning positions, because a removal of 1, ..., 5 marbles leaves the opponent in the losing position with 38 marbles.

However, is again a losing position, because one would need to remove , , , , , or all 44 marbles to force the opponent into a losing position, but these moves are not allowed.

The next five numbers, 45, ..., 49 are winning positions, because a removal of 1, ..., 5 marbles leaves the opponent in the losing position with 44 marbles.

Now the number 50 is left and it is again a losing position, because Alfred would need to remove , , , , , , or all 50 marbles to bring Bodil into a losing position, but these moves are not allowed. Hence Bodil will win the game if she plays in an optimal way.
Final answer
Bodil

Techniques

Games / greedy algorithmsInvariants / monovariantsInduction / smoothing