Fibonacci
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
Following is the recursive definition of Fibonacci sequence:
Now we need to check whether a number can be expressed as the product of numbers in the 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
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
题意:问一个数n,能否由斐波那契数列中的某些数乘积组成;
思路:打表,能组成的全弄出来;
#include<bits/stdc++.h> using namespace std; #define ll long long #define pi (4*atan(1.0)) #define eps 1e-14 const int N=2e5+10,M=4e6+10,inf=1e9+10,mod=1e9+7; const ll INF=1e18+10; map<ll,int>m; ll f[N]; priority_queue<ll,vector<ll>,greater<ll> >q; void init() { int pre=0; int now=1; f[0]=0; f[1]=1; for(int i=2;i<=44;i++) f[i]=f[i-1]+f[i-2]; for(int i=0;i<=44;i++) if(!m[f[i]]) q.push(f[i]),m[f[i]]=1; while(!q.empty()) { ll v=q.top(); q.pop(); for(int i=1;i<=44;i++) { if(f[i]*v<inf&&!m[f[i]*v]) { m[f[i]*v]=1; q.push(f[i]*v); } } } } int main() { init(); int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); if(m[n]) printf("Yes "); else printf("No "); } return 0; }