hdoj-5167-Fibonacci
来源:互联网 发布:温什么知什么的成语 编辑:程序博客网 时间:2024/05/21 06:41
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.
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
For each test case , the first line contains a integers n , which means the number need to be checked.
Output
For each case output "Yes" or "No".
Sample Input
3417233
Sample Output
YesNoYes
一定会要先打表把所有的斐波那契数求出来,然后直接dfs就ok了,然后又点剪枝
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;typedef long long ll;#define N 100000ll f[N],n;int cnt;bool flag;void init(){ f[0]=0; f[1]=1; cnt=2; for(; f[cnt-1]<=1000000000; cnt++) f[cnt]=f[cnt-1]+f[cnt-2];}void dfs(ll k,int num){ if(k==1){ flag=true; return; } for(int i=num;i>=3;i--) { if(f[i]>k) continue; if(k%f[i]==0) dfs(k/f[i],i); if(flag) return; }}int main(){ init(); int t; scanf("%d",&t); while(t--) { scanf("%lld",&n); if(!n||n==1) printf("Yes\n"); else { flag=false; dfs(n,cnt-1); if(flag) printf("Yes\n"); else printf("No\n"); } } return 0;}
0 0
- 【BestCoder】 HDOJ 5167 Fibonacci
- hdoj-5167-Fibonacci
- HDOJ 1021: Fibonacci Again
- HDOJ 1021 Fibonacci Again
- HDOJ 1588 - Gauss Fibonacci
- HDOJ 3117 - Fibonacci Numbers
- HDOJ 1021 Fibonacci Again
- HDOJ 1021 Fibonacci Again
- 【HDOJ】1708 -> Fibonacci String
- HDOJ Fibonacci Again
- HDOJ 1021 Fibonacci Again
- HDOJ 1021 Fibonacci Again
- hdoj 1021 Fibonacci Again
- hdoj 1021 Fibonacci Again
- hdoj 1568 Fibonacci
- HDOJ 4786 Fibonacci Tree
- HDOJ 1021 Fibonacci Again
- hdoj 1021 Fibonacci Again
- 顺心随笔NO.1
- MYSQL 浅谈MyISAM 存储引擎
- 关于Cool Compiler
- Android分发机制深入解析
- win10+Ubuntu16.04双系统
- hdoj-5167-Fibonacci
- Redis笔记三之Java操作Redis
- hdu 1281 棋盘游戏 二分图匹配 匈牙利算法 解题报告
- django学习笔记一
- 使用Android Studio开发NDK
- InnoDB与MyISAM的六大区别(转)
- URAL 2024 Adventure Time 思维题、Interesting
- Java容器四:Hashtable
- 七牛的存储算法猜测