Problem description
There are two piles of stones, which can be different in quantity. The game started with taking stones in turn by two people. The game stipulates that there are two different methods to get each time. One is to remove any number of stones from any pile; the other is to take the same number of stones from both piles. Finally, the winner of all the stones. Now we will give you the initial number of two stones. If it is your turn to take them first, let us assume that both Parties adopt the best strategy and ask whether you are the winner or the loser at last. If you win, how do you get a child for 1st times?
Input
The input contains several rows, indicating the initial condition of several stones. Each row contains two non-negative integers, A and B, indicating the number of two stones. Neither a nor B is greater than 1,000,000, and a <= B. A = B = 0 exit.
Output
The output also has several rows. If you are the loser at last, it is 0. Otherwise, output 1, and output the number of the remaining two piles of stones X, Y, x <= y after you win 1st times. If you take the same number of stones away from any pile, you can win the same number of stones at the same time in both piles. First, you can output the situation of taking the same number of stones away.
Sample Input
1 2
5 8
4 7
2 2
0 0
Sample output
0
1
4 7
3 5
0
1
0 0
1 2
If you win the game, the trouble is to write the number of remaining stones for the first time.
Reference code:
# Include <iostream> # include <cmath> using namespace STD; int lostp [381968] [2]; double GM = (1.0 + SQRT (5.0)/2.0; int main () {int I, A, B, D; for (I = 0; I <381968; ++ I) {lostp [I] [0] = int (I * GM); lostp [I] [1] = lostp [I] [0] + I ;} while (scanf ("% d", & A, & B), a | B) {d = B-; if (d <381968 & lostp [d] [0] = A) {printf ("0 \ n"); continue;} printf ("1 \ n "); // you should have a good understanding of the nature of the weizov game from here, the third property is if (d <381968 & A> = lostp [d] [0] & B> = lostp [d] [1]). printf ("% d \ n", lostp [d] [0], lostp [d] [1]); for (I = 0; I <381968; ++ I) // simple enumeration after analysis {If (lostp [I] [0] = A | lostp [I] [1] = A | lostp [I] [0] = B | lostp [I] [1] = B) {if (a> lostp [I] [0] | B> lostp [I] [1]) {printf ("% d \ n ", lostp [I] [0], lostp [I] [1]); break;} If (lostp [I] [0]> B) break ;}}} return 0 ;}
Weizov game: http://blog.csdn.net/no_retreats/article/details/7904531