Division Game
Time limit1sMemory limit128 MB
Decide whether the first player wins a game that divides chosen entries of one matrix row per move.
- Level
Medium7 of 10
- Topics
- Game theory, Number theory, Math
- Solved
- No attempts yet
Problem
Division game is a game for two players. The board is an matrix of positive integers.
The players move in turns. The player to move first picks one row. If every entry of that row is 1, that player loses. Otherwise the player picks at least one entry greater than 1 from that row and divides each picked entry by one of its own divisors other than 1. Different entries may use different divisors. For example, 6 can be divided by 2, 3 and 6, but it cannot be divided by 1, 4 or 5.
The player who first turns every entry of the matrix into 1 wins. In other words, the player who is handed a matrix of all 1s loses.
Both players play as well as they can. Given the matrix, decide whether the first player wins.
Input
The first line has the number of test cases , a positive integer at most .
The first line of each test case has the number of rows and the number of columns , both between and inclusive. Each of the next lines has integers, and every one of those integers is between and inclusive.
Output
For each test case, print one line holding Case #x: YES or Case #x: NO, where is the test case number starting from 1. Print YES when the first player has a winning strategy and NO when the first player does not.