Fibonacci

3 篇文章 0 订阅

         题记:这个是bc的B题,一开始思路局限了,只认为这个数比较大,

就什么__int64接受这类的的接受,根本没想到什么DFS搜索算法,想想还

是题目做得太少,后来同我同学一讲,觉得的确在理,本身Fibonacci在第

45个数的时候就已经很大了,这是通过打表来实现,就是所谓的在正式运

算之前,先通过算法计算数据的大小。所以用搜索还是可以实现的。后来

一直报错,就一直比较,一直提交,最后发现原来是数据接收定义的时候

调用函数和原本函数的定义元素一样,导致了数据混乱,

看来以后得注意分别定义

             关于题目:本题目的含义为输入一个数,判定它是否可以用斐波那

契树的乘积来表示;总体思路就是枚举这45个数,然后从大到小一个个接受,

若能整除,就继续接受小于等于他的树,判定能否整除,若最后能全部整除

,就标明这个数可以被整除,若循环结束仍然没有返回,就标明不能被整除

,输出No.值得注意的是0.当输入0时,直接输出Yes.

 

Fibonacci

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 855    Accepted Submission(s): 229


Problem Description
Following is the recursive definition of Fibonacci sequence:
Fi=01Fi1+Fi2i = 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. ( T100,000 )
For each test case , the first line contains a integers n , which means the number need to be checked.
0n1,000,000,000
 

Output
For each case output "Yes" or "No".
 

Sample Input
  
  
3 4 17 233
 

Sample Output
  
  
Yes No Yes
  感想:

Source
BestCoder Round #28
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int fun[1001];
int DFS(int n,int shu)
{
    int s,i;
    if(n==1)
    return 1;
    for(i=shu;i>=3;i--)
    {
        if(n%fun[i]==0)
        {
            s=DFS(n/fun[i],i);
            if(s)
            return 1;
        }
    }
    return 0;
}
int main()
{
    int a,i;
    fun[0]=0;
    fun[1]=1;
    for(i=2;i<=45;i++)
    fun[i]=fun[i-1]+fun[i-2];
    scanf("%d",&a);
    while(a--)
    {
        int n;
        scanf("%d",&n);
        if(n==0)
        printf("Yes\n");
        else if(DFS(n,45)==true)
        printf("Yes\n");
        else
        printf("No\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值