Among the general questions of OI Lin, I have the biggest headache of the game. What is optimal choice? What is the winning strategy? Dizzy/O \...
The tragedy is that this question is added to the test questions of teacher C... For me that only outputs "0" (of course, the even number can only be 1 and I also found ~), The phrase "this question must be answered" in the question is doomed to the tragic fate of my test...
[Description]
Here there are K stones (3 <= k <= 10 ^ 10), two people take turns to take these stones. A maximum of 1 block (L> 0) can be obtained each time, and a minimum of 1 block can be obtained. For the input K, determine whether there is an L, so that the second operator has a winning strategy. If yes, the minimum output L; if not, the output 0.
[Input format]
The first behavior is a positive integer T, indicating the number of groups of data. Next t rows, each row has a positive integer k (1 <=t <= 1000)
[Output format]
T rows are output, which is the answer to T group data. Each behavior meets the minimum limit of L or 0.
[Example input]
1
3
[Sample output]
2
According to my classmates, it's a very easy game... You can look down on the kids shoes that you cannot start.
Obviously, if K is an even number, the result must be 1 (that is, one by one ). But what about even numbers?
Simple analysis, if each get a K-1, then the second take will certainly win. However, the question requires a solution. With the above analysis results, we can convert the questions.
We have 15 stones. Because we know that the winning strategy of "getting K-1 each time", then we can convert the overall winning to local winning, that is, group them.
First, they are divided into three groups. If you get 4 at a time, the second one wins.
Second, we can divide them into five groups, so that each time we take two, the second will win.
Because the question requires the minimum output of L, our task becomes to find the minimum approximate number of K. That is why the answer to an even number is 1.
The main difficulty is finding an appointment. It can be proved that the minimum approximate number must be a prime number. If the data range is large, we can create a prime number table ranging from 1 to 10 ^ 5. Well, that's it.
Reference Code (omitting the prime number table ):
1 program game;
2 const
3 Z: array [1 .. 9592] of longint = (prime number table );
4 VaR
5 I, j: longint;
6 K, P, T: int64;
7 begin
8 readln (t );
9 For I: = 1 to t do
10 begin
11 P: = 0;
12 readln (k );
13 For J: = 1 to 9592 do // simple enumeration
14 if K mod z [J] = 0 then
15 begin
16 P: = J;
17 break;
18 end;
19 if p = 0 then writeln (k-1) // process large prime numbers
20 else writeln (Z [p]-1 );
21 end;
22 end.
(Saltless original, reprinted please indicate the source)