LDU 个人训练赛二 I Interesting Integers

Undoubtedly you know of the Fibonacci numbers. Starting with F1 = 1 and F2 = 1, every next number is the sum of the two previous ones. This results in the sequence 1, 1, 2, 3, 5, 8, 13, . . .. Now let us consider more generally sequences that obey the same recursion relation Gi = Gi−1 + Gi−2 for i > 2 but start with two numbers G1 ≤ G2 of our own choice. We shall call these Gabonacci sequences. For example, if one uses G1 = 1 and G2 = 3, one gets what are known as the Lucas numbers: 1, 3, 4, 7, 11, 18, 29, . . .. These numbers are – apart from 1 and 3 – different from the Fibonacci numbers. By choosing the first two numbers appropriately, you can get any number you like to appear in the Gabonacci sequence. For example, the number n appears in the sequence that starts with 1 and n − 1, but that is a bit lame. It would be more fun to start with numbers that are as small as possible, would you not agree?

Input

On the first line one positive number: the number of test cases, at most 100. After that per test case: • one line with a single integer n (2 ≤ n ≤ 109 ): the number to appear in the sequence.

Output

Per test case: • one line with two integers a and b (0 < a ≤ b), such that, for G1 = a and G2 = b, Gk = n for some k. These numbers should be the smallest possible, i.e., there should be no numbers a 0 and b 0 with the same property, for which b 0 < b, or for which b 0 = b and a 0 < a. Sample in- and output

Input

5

89

123

1000

1573655

842831057

Output

1 1

1  3

2 1 

985 1971

2 7

题目大意:给你一个数列的某一项,需要将第一项和第二项写出来,每一项都是由斐波那契数列那样推出

思路:每一项都由第一项和第二项表示,就会根据规律发现,每一项前面的系数都是斐波那契数列。由此可以根据枚举的方法来计算

#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll vis[100];
int main()
{
    int t;
    ll n;
    vis[0]=0;
    vis[1]=vis[2]=1;
    for(int i=3;i<=45;i++)
    {
        vis[i]=vis[i-1]+vis[i-2];
        //printf("%d\n",vis[i]);
    }
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        int flag=0;
        for(int i=45;i>=0;i--)
        {
            ll t,mm;
            t=n/vis[i];
            mm=vis[i-1]+vis[i];
            for(int j=1;j<=t+1;j++)
            {
                if((n-mm*j)%vis[i]==0&&(n-mm*j)>0)
                {
                    int a,b;
                    a=j;
                    b=(n-mm*j)/vis[i];
                    if(b<=a&&b!=0)
                    {
                        printf("%d %d\n",b,a);
                        flag=1;
                        break;
                    }

                }
            }
            if(flag)
                break;
        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值