Problem description Any college student should not be unfamiliar with the Fibonacci (Fibonacci numbers), which is defined as:
F (1) = 1;
F (2) = 2;
F (n) =f (n-1) +f (n-2) (n>=3);
So, 1,2,3,5,8,13 ... is the Fibonacci series.
There are a lot of related topics in hdoj, such as 1005 Fibonacci again is once the Zhejiang province game problem.
Today, another topic about Fibonacci appears, it is a small game, defined as follows:
1, this is a two-person game;
2, a total of 3 piles of stones, the number is M, N, p;
3, two people take turns;
4, each step can choose any heap of stones, and then take away F;
5, F can only be the element in the Fibonacci sequence (that is, each time only take 1,2,3,5,8 ... Quantity);
6, the first to take the light of all the stones of the person who wins;
Assuming both sides use the optimal strategy, judge whether the person who wins the game will win or the person who will win.
Input data contains multiple test cases, one row for each test case, and 3 integer m,n,p (1<=m,n,p<=1000).
M=n=p=0 indicates the end of the input.
Output if the initiator can win, please export "Fibo", otherwise output "Nacci", the output of each instance occupies one row.
Sample INPUT1 1 11 4 10 0 0
Sample Outputfibonacci
#include <iostream>#include<cstring>#definell Long Longusing namespacestd;intf[ the]={1,2,3,5,8, -, +, the, -, the,144,233,377,610,987};intsg[1005];BOOLhas[1005];voidGETSG () {memset (SG,0,sizeof(SG)); for(intI=1; i<= +; i++) {memset (Has,false,sizeof(has)); for(intj=0;j< the; j + +) { if(f[j]<=i) has[sg[i-f[j]]]=true; } for(intj=0; j<= +; j + +) { if(has[j]==false) {Sg[i]=J; Break; } } }}intMain () {intn,m,p; GETSG (); //cout<< "ll" <<endl; while(cin>>n>>m>>p) {if(n==0&&m==0&&p==0) Break; intans=0; Ans=ans^sg[n]^sg[m]^Sg[p]; if(ans) cout<<"Fibo"<<Endl; Elsecout<<"Nacci"<<Endl; } return 0;}
Hdu 1848 Fibonacci again and again (simple SG)