Hust oj 1720 Fibonacci Numbers(水题)

Fibonacci Numbers
Time Limit: 1000 MSMemory Limit: 32768 K
Total Submit: 140(68 users)Total Accepted: 90(68 users)Rating: Special Judge: No
Description

We all know Fibonacci Numbers: F0=1, F1=1, F2=F1+F2, ..., Fi=F(i-1)+F(i-2).

Now, given a positive integer n(0<=n<=1000 000 000), can you find three different Fibonacci number Fa, Fb, Fc(a<b<c), which can make n=Fa+Fb+Fc?


Input

There are multiple test cases. The first line is an integer T indicating  the number of test cases. Each test case has one line, with a positive integer n.

Output

If there is any Fa, Fb, Fc, which can suffice n = Fa+Fb+Fc, output Fa, Fb, Fc in one line. If there are multiple groups, output the smaller one by lexicographical order. 

If there is no sufficed group output "Not Found!".

Sample Input

9

1

2

3

4

5

6

7

8

9

Sample Output

Not Found!

Not Found!

Not Found!

1 1 2

1 1 3

1 2 3

1 1 5

1 2 5

1 3 5 

fib数列到第45个会超过10e9,暴力跑一边就可以

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

const int Maxn = 100;
typedef long long int ll;
ll fib[Maxn];

void init()
{
    fib[0] = 1;
    fib[1] = 1;
    for(int i=2;i<=45;i++)
        fib[i] = fib[i-1] + fib[i-2];
}

int main()
{
    ll n;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld",&n);
        int flag = 0;
        int i,j,k;
        init();
        for(i=0;i<=45;i++)
        {
            for(j=i+1;j<45;j++)
            {
                for(k=j+1;k<44;k++)
                {
                    if(fib[i] + fib[j] + fib[k] == n)
                    {
                        flag = 1;
                        break;
                    }
                }
                if(flag == 1)
                    break;
            }
            if(flag == 1)
                break;
        }
        if(flag == 0)
            printf("Not Found!\n");
        else
            printf("%lld %lld %lld\n",fib[i],fib[j],fib[k]);
    }
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值