Problem Description
1 Heap of stones There are N, two people take turns. The 1th time the first person can take any number, but not all of them. The number of stones to be taken at a later time cannot exceed twice times the number of previous fetching. The winner wins. The first to take the negative output "Second win". The first winner wins the output.
Input
The input has more than one group. The 1th row of each group is 2<=n<2^31. N=0 exit.
Output
First take the negative output "Second win". The first winner wins the output.
See sample Output.
Sample Input
2
13
10000
0
Sample Output
Second win
Second win
First win
Analysis
First fetch: The person after a: B
2 stones: A must lose, B wins.
3 stones: A takes 1 or two, or loses, B wins.
4 Stones: A can take 1 stones for the first time to win, a wins.
5 stones: A first Take 1, then B can only take 1, so that the situation into 3 stones, b wins; a first take 2, B wins.
6 Stone When: a first take 1, then B then take 1, the situation becomes 4 stone situation, a wins, if B take 2, only 3 A can be taken out, a wins.
7 Stones: A first take 2, then B then take 1, leaving 4 stones, a win, if B take 2 or 3 or 4, the remaining a can be taken at once, a wins.
8 stones: A For the first time to take 1, B can take 2, leaving 5 stones, b wins; a first take 2, B can go 1, the remaining 5 stones, b wins; a first take 3, B can be taken out, B wins.
And so on, you can find that when the number of pebbles is the number in the Fibonacci sequence, B can win, or a can win.
#include <iostream>using namespacestd;intMain () {//2^31 =2147483648 Long Long inta[ $];//a[44]=2971215073a[0]=2, a[1]=3; Long Long intN; for(intI=2;i< $; i++) A[i]=a[i-1]+a[i-2]; while(Cin>>n && n!=0) { inti; for(i=0;i< $; i++) if(n==A[i]) Break; if(i> -) cout<<"First win"<<Endl; Elsecout<<"Second Win"<<Endl; } return 0; }
HDU 2516 take the stone game