HDU 5167 Fibonacci (bestcoder Round #28)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.