Two players alternately remove every copy of one prime factor from the current number, and whoever faces a number whose digit sum is 1 or prime loses.
Medium7Game theoryNumber theoryMathNo attempts yetTime limit5sMemory limit512 MBGooglers love numbers, and they love games built on numbers even more. Two Googlers, Laurence and Seymour, invented a two player game around gNumbers. A number is a gNumber when the sum of its digits has no positive divisor other than 1 and itself. By that definition 1 is a gNumber.
The game runs like this. Someone who is not playing picks a starting number N. The two players then alternate turns. On a turn the player checks whether the current number C is a gNumber. If it is, that player loses at once. Otherwise the player picks a prime factor P of C and divides C by P repeatedly until P no longer divides it. For example, with a current number of 72 the player can pick 2 and divide down to 9, or pick 3 and divide down to 8. The result of the division becomes the new current number, and the other player takes a turn.
Laurence always moves first, and he hates to lose. Given N, determine which player wins when both play optimally.
The first line contains the number of test cases T. Each of the next T lines contains one starting number N.
For each test case, print one line in the form "Case #x: y", where x is the test case number starting from 1 and y is the winner's name, either Laurence or Seymour.
For N=2 the digit sum is 2, and 2 has no positive divisor other than 1 and itself, so 2 is already a gNumber. Laurence loses immediately and Seymour wins. The same holds for N=3.
For N=4 the digit sum is 4, and 4 has the positive divisor 2 besides 1 and itself, so 4 is not a gNumber. The only prime factor of 4 is 2, so Laurence must pick 2 and divide until 1 is left. Seymour then starts his turn on 1, which is a gNumber, so Seymour loses and Laurence wins.