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. Servlet问题:servlet cannot be resolved to a type解决办法

    工程里的路径权限高,并且eclipse并到classpath里寻找jar位置,所以我就到我的java项目里 项目名-->右键 Property-->选择 Java Build Path-- ...

  2. DataTables 配置和使用

    WEB后台开发,如果用的是Bootstrap框架,那这个表格神器你一定不要错过. 官方地址:https://datatables.net/ What?英文不好,没关系咱有中文的 http://data ...

  3. JavaScript的68个技巧一

    1. 严格模式 在自己的项目中 你可以坚持只使用" 严格模式 " 或只使用" 非严格模式 "的策略.但如果你要编写健壮的代码应对各种各样的代码连接 你有两个可选 ...

  4. Cortex-mo指令集

    处理器使用的是ARMv6-M Thumb指令集,包括大量的32位的使用Thumb-2技术的指令.表7-22列出了Cortex-M0指令和它们的周期数.周期计数以零等待状态的系统为基准. 表7-22  ...

  5. datagrid数据导出到excel文件给客户端下载的几种方法

    方法一:导出到csv文件,存放在服务器端任一路径,然后给客户下载 优点: 1.可以进行身份认证后给客户下载,如果放到非web目录就没有对应的url,客户无法随时下载. 2.也是因为生成了文件,所以占用 ...

  6. .IIS7如何设置301重定向详解

    <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.we ...

  7. 使用VS Code开发AngularJS 2 第一个应用程序

    使用VS Code开发AngularJS 2 第一个应用程序 目录 运行环境 创建项目 安装依赖包 创建TypeScript应用程序 配置应用程序 运行应用程序 运行环境 运行环境: Windows ...

  8. u盘启动盘制作工具

    u盘启动盘制作工具http://www.dabaicai.biz/ 系统镜像文件下载:http://xt.qingdiangongsi.cn/xtxz/

  9. defer和async

    1.decument.wirte不能使用 2.<script src="text.js" type="text/javascript" defer=&qu ...

  10. 第1章 网络编程基础(2)——Socket编程原理

    Socket编程原理 Socket是网络通信端点的一种抽象,它提供了一种发送和接收数据的机制. 流socket(SOCK_STREAM):双向.有序.无重复.并且无记录边界 数据报Socket(SOC ...