hdu-5167 Fibonacci

链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=5167


Fibonacci

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 474    Accepted Submission(s): 126


Problem Description
Following is the recursive definition of Fibonacci sequence:
Fi=01Fi1+Fi2i = 0i = 1i > 1

Now we need to check whether a number can be expressed as the product of numbers in the Fibonacci sequence.
 

Input
There is a number  T  shows there are  T  test cases below. ( T100,000 )
For each test case , the first line contains a integers n , which means the number need to be checked. 
0n1,000,000,000
 

Output
For each case output "Yes" or "No".
 

Sample Input
  
  
3 4 17 233
 

Sample Output
  
  
Yes No Yes
 


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include <sstream>
#include <time.h>
#include <utility>
#include <malloc.h>

using namespace std;

__int64 p[100];
int T;
__int64 n;

int main()
{
    p[0] = 0; p[1] = 1;
    for (int i = 2; i <= 46; i++)
        p[i] = p[i - 1] + p[i - 2];

    set<__int64> q;
    set<long long> ::iterator it;
    q.clear();
    q.insert(0);
    q.insert(1);
    for(it=q.begin();it!=q.end();it++)
    {
         for(int j=3;j<=45;j++)
        {
            int tt = *it;
            __int64 tmp = tt*p[j];
            if (tmp <= 1000000000)
                q.insert(tmp);
        }
    }
    cin>>T;
    while (T--)
    {
        int ok=0;
        cin>>n;
        if (q.find(n) != q.end())
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值