Fibonacci
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2145 Accepted Submission(s): 549
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.
F
i
=⎧
⎩
⎨
0
1
F
i−1
+F
i−2![]()
![]()
i
= 0
i
= 1
i
> 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
数据卡的很死,自己怎么做也没A掉。【后来找到了AC代码测数据,确实有bug存在】
没办法,只能另挑路径了。
代码很好理解,这里直接上代码:
#include<stdio.h>
#include<string.h>
using namespace std;
typedef long long ll;
ll f[50];
void init() {
f[0] = 0;
f[1] = 1;
for(int i = 2; i <= 45; i++) {
f[i] = f[i-1] + f[i-2];
}
}
bool dfs(ll n,int x)
{
if(n<=3)return true;
for(int i=3;i<=x;i++)
{
if(n%f[i]==0)
{
if(dfs(n/f[i],i))
return true;
}
}
return false;
}
int main()
{
init();
ll n;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
if(dfs(n,45))
printf("Yes\n");
else
{
printf("No\n");
}
}
}