Stone Game 8
Time limit1sMemory limit128 MB
Count pile sizes up to M where the second player wins a take-away game with a fixed move set.
- Level
Medium6 of 10
- Topics
- Game theory, Dynamic programming, Math
- Solved
- No attempts yet
Problem
The stone game is a game where two people take stones in alternating turns.
There are stones on a table. Sanggeun and Changyoung take stones one after the other, and the numbers of stones a player may take in one turn are fixed in advance. A player who cannot take one of the allowed numbers of stones on their turn loses the game. Sanggeun goes first, and both players play as well as they possibly can.
Given and the numbers of stones a player may take in one turn, write a program that counts how many values of between and let Changyoung win.
Input
The first line contains . ()
The second line contains the number of allowed moves . ()
The third line contains the numbers of stones a player may take in one turn, separated by spaces. Each number is at least and at most , no number repeats, and they are given in increasing order.
Output
Print how many values of let Changyoung win. ()