Problem Description
Following is the recursive definition of Fibonacci sequence:

Fi=⎧⎩⎨01Fi−1+Fi−2i = 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. (T≤100,000) For each test case , the first line contains a integers n , which means the number need to be checked.  0≤n≤1,000,000,000
 
Output
For each case output "Yes" or "No".
 
Sample Input
3 4 17 233
 
Sample Output
Yes No Yes
 
Source
 
 
 
题意:判断一个数能否由任意个菲波那媞数相乘得到,能的话输出“Yes”,否则输出“No”
思路:首先要处理菲波那媞数组,然后用一个队列来实现菲波那媞数的相乘,用一个map数组来标记。具体看代码
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
#define N 46
#define ll long long
ll f[N];
map<ll,bool>mp;
void init()
{
mp.clear();
queue<ll>q;
f[]=;
f[]=;
mp[]=true;
mp[]=true;
q.push();
q.push();
for(int i=;i<N;i++)
{
f[i]=f[i-]+f[i-];
mp[f[i]]=true;
q.push(f[i]);
}
while(!q.empty())
{
ll tmp=q.front();
q.pop();
for(int i=;i<N;i++)
{
ll cnt=tmp*f[i];
if(cnt>1000000000L)
break;
if(mp[cnt]) continue;
mp[cnt]=true;
q.push(cnt);
}
} }
int main()
{
init();
int t;
scanf("%d",&t);
while(t--)
{
ll n;
scanf("%I64d",&n);
if(mp[n]==true)
printf("Yes\n");
else
printf("No\n"); }
return ;
}

hdu 5167 Fibonacci(预处理)的更多相关文章

  1. HDU 5167 Fibonacci 筛法+乱搞

    题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5167 题意: 给你一个x,判断x能不能由斐波那契数列中的数相乘得到(一个数可以重复使用) ...

  2. hdu 5167 Fibonacci 打表

    Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Proble ...

  3. HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)

    HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意:  求第n个斐波那契数的 ...

  4. hdu 3117 Fibonacci Numbers 矩阵快速幂+公式

    斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...

  5. hdu Interesting Fibonacci

    Interesting Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  6. hdu 3117 Fibonacci Numbers

    这道题其实也是水题来的,求Fibonacci数的前4位和后4位,在n==40这里分界开.后4位不难求,因为n达到了10^18的规模,所以只能用矩阵快速幂来求了,但在输出后4位的时候一定要注意前导0的处 ...

  7. hdu 4786 Fibonacci Tree (2013ACMICPC 成都站 F)

    http://acm.hdu.edu.cn/showproblem.php?pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others) ...

  8. hdu 1021 Fibonacci Again(找规律)

    http://acm.hdu.edu.cn/showproblem.php?pid=1021 Fibonacci Again Time Limit: 2000/1000 MS (Java/Others ...

  9. HDU 4786 Fibonacci Tree 最小生成树

    Fibonacci Tree 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4786 Description Coach Pang is intere ...

随机推荐

  1. 性能计数器自动收集-logman

    1.在桌面云测试中,往往需要模拟并发连接中服务器的性能数据,这里主要介绍如何自动收集性能数据 2.创建xxxx.bat文件,文件内容如下: logman create counter test -cf ...

  2. IIS7.0 Windows Server 2008 R2 下配置证书服务器和HTTPS方式访问网站

    配置环境 Windows版本:Windows Server 2008 R2 Enterprise Service Pack 1 系统类型: 64 位操作系统 了解HTTPS 为什么需要 HTTPS ? ...

  3. Windows移动开发(二)——闭关修炼

    一些武侠小说里的大人物,为了争夺武林盟主,号召天下,常常闭关修炼一段时间,闭关期间仅仅能接触送饭的人,而且关外还有非常多守卫的人员.还有,不管是篮球还是足球运动员,他们在真正接触球之前,都必须做非常长 ...

  4. Oracle11g完全卸载步骤

    Oracle11g完全卸载步骤:1. 开始->设置->控制面板->管理工具->服务 停止所有Oracle服务.2. 开始->程序->Oracle - OraHome ...

  5. Window 10通过网线和Wifi连接树莓派

    几个月前买了个树莓派,扔在一边没有捣鼓,今天搞定了笔记本通过家里的wifi登录树莓派,下面列出设置过程. 实验环境: 网络:只有wifi 材料:笔记本一台(Win10),树莓派一台,EDUP USB无 ...

  6. Java设计模式---(动态)代理模式

    代理设计模式 定义:为其他对象提供一种代理以控制对这个对象的访问. 动态代理使用 java动态代理机制以巧妙的方式实现了代理模式的设计理念. 之前虽然会用JDK的动态代理,但是有些问题却一直没有搞明白 ...

  7. iframe 元素

    iframe 元素会创建包含另外一个文档的内联框架(即行内框架). 可以访问:http://www.w3school.com.cn/tags/tag_iframe.asp

  8. ORACLE中将数字转换为英文

    SELECT LEVEL, to_char(to_date(LEVEL,'J'),'Jsp') FROM dual CONNECT 运行结果如下图所示:   说明: TO_CHAR(aDate,'JS ...

  9. java日期操作

    //字符串转日期 public static void dt7() throws ParseException { String str_date="2015---08---08" ...

  10. 第1章 网络编程基础(3)——基本Socket通信

    服务器常用模型