Problem Description:
Following is the recursive definition of Fibonacci sequence:
FI=???01Fi− 1+ fi−2< Span id= "mathjax-span-15" class= "mtext" >i = 0i = 1i > 1
Now we need to check whether a number can is expressed as the product of numbers in the Fibonacci sequence.Input:there is a numberTShows there isTTest cases below. (T≤ )
For each test case, the first line contains a integers n, and which means the number need to be checked.
0≤n≤1 , Output:for each case output "Yes" or "No". Sample input:3417233 Sample Output:yesnoyes
Test instructions: Determines whether a number n is the product of the number of Fibonacci sequences (which can be the same number).
#include <stdio.h>#include<string.h>#include<queue>#include<math.h>#include<stdlib.h>#include<algorithm>using namespacestd;Const intn=1e6+Ten;Const intinf=0x3f3f3f3f;Const intMod=1e9;typedefLong LongLL; LL N, a[ -];intk, Flag;voidSolve ()///hit the table and find the subscript k that satisfies the maximum Fibonacci number of the test instructions{ inti; a[0] =0; a[1] =1; for(i =2; I <= -; i++) {A[i]= a[i-1]+a[i-2]; if(A[i] >=MOD) { if(A[i] > MOD) i--; K=i; Break; } }}voidDFS (intnum, LL m) { inti; if(M = =1) flag =1; if(Flag = =1) return ; if(Num <3)return ; if(m% a[num] = =0) DFS (num, M/A[num]); DFS (Num-1, M);}intMain () {intT; Solve (); scanf ("%d", &T); while(t--) {scanf ("%lld", &N); Flag=0; if(n = =0) {printf ("yes\n"); Continue; } DFS (k, n); if(Flag = =1) printf ("yes\n"); Elseprintf"no\n"); } return 0;}
HDU 5167 Fibonacci (bestcoder Round #28)