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 10

985 1971

2 7

解题:斐波那契第n项:a[n]=f[n-1]*x+f[n]*y;       //  f[n]:f[1]=0,f[2]=1;的斐波那契数列。枚举n与y看是否能整除f[n-1]。且除数<=y。

x:斐波那契第一项。y:斐波那契第二项。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define Max(a,b) (a>b?a:b)
using namespace std;
#define ll long long
int main (void)
{
int f[1005] , ans ;
int y ,x;
f[1]=0;
f[2]=1;
int i=3;
for( i=3; i<=46; i++)
{
f[i]=f[i-1]+f[i-2];
}
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&ans);
if(ans==1||ans==2)
{
printf("1 1\n");
continue;
}
bool bb=0;
for(int i=45 ; i>2&&!bb; i--)
for(int ty=1; ty<=1000000; ty++)
if(ty*f[i]+f[i-1]>ans)
break;
else if((ans-ty*f[i])%f[i-1]==0&&(ans-ty*f[i])/f[i-1]<=ty)
{
y=ty , x=(ans-ty*f[i])/f[i-1] , bb=1;
break;
}
printf("%d %d\n",x,y);
}
return 0;
}

HUNAN Interesting Integers(爆力枚举)的更多相关文章

  1. 【扩展欧几里得】BAPC2014 I Interesting Integers (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  2. interesting Integers(数学暴力||数论扩展欧几里得)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAwwAAAHwCAIAAACE0n9nAAAgAElEQVR4nOydfUBT1f/Hbw9202m0r8

  3. GYM100526I Interesting Integers

    题目大意 定义一种 \(Gabonacci\) 数列: \[\begin{array}{c} G_1=a\\ G_2=b\\ G_i=G_{i-1}+G_{i-2} \end{array} \] 给定 ...

  4. 计蒜客 28319.Interesting Integers-类似斐波那契数列-递推思维题 (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 I)

    I. Interesting Integers 传送门 应该是叫思维题吧,反正敲一下脑壳才知道自己哪里写错了.要敢于暴力. 这个题的题意就是给你一个数,让你逆推出递推的最开始的两个数(假设一开始的两个 ...

  5. Google kickstart 2022 Round A题解

    Speed Typing 题意概述 给出两个字符串I和P,问能否通过删除P中若干个字符得到I?如果能的话,需要删除字符的个数是多少? 数据规模 \[1≤|I|,|P|≤10^5 \] 双指针 设置两个 ...

  6. 解剖SQLSERVER 第十七篇 使用 OrcaMDF Corruptor 故意损坏数据库(译)

    解剖SQLSERVER 第十七篇 使用 OrcaMDF Corruptor 故意损坏数据库(译) http://improve.dk/corrupting-databases-purpose-usin ...

  7. 2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution

    A:Exam Solved. 温暖的签. #include<bits/stdc++.h> using namespace std; ; int k; char str1[maxn], st ...

  8. ACM 第十七天

    暑期热身赛 BAPC 2014 The 2014 Benelux Algorithm Programming Contest 题目网址:https://odzkskevi.qnssl.com/3655 ...

  9. Benelux Algorithm Programming Contest 2014 Final

    // Button Bashing (bfs) 1 #include <iostream> #include <cstdio> #include <cstring> ...

随机推荐

  1. Linux中权限(r、w、x)对于目录与文件的意义

    Linux中权限(r.w.x)对于目录与文件的意义 一.权限对于目录的意义 1.首先要明白的是目录主要的内容是记录文件名列表和子目录列表,而不是实际存放数据的地方. 2.r权限:拥有此权限表示可以读取 ...

  2. touchSlider插件案例

    <!doctype html> <html lang="en"> <head> <title>jQuery手机图片触屏滑动轮播效果代 ...

  3. 结构型设计模式之外观模式(Facade)

    结构 意图 为子系统中的一组接口提供一个一致的界面,F a c a d e 模式定义了一个高层接口,这个接口使得这一子系统更加容易使用. 适用性 当你要为一个复杂子系统提供一个简单接口时.子系统往往因 ...

  4. Linux将命令添加到PATH中【转】

    转自:http://www.jb51.net/LINUXjishu/150167.html 电脑中必不可少的就是操作系统.而Linux的发展非常迅速,有赶超微软的趋势.这里介绍Linux的知识,让你学 ...

  5. 多线程之:ThreadLocal

    Java中ThreadLocal类可以使创建的变量只被同一个线程进行读和写操作,即使有多个线程同时执行同一段代码,并且这段代码中又有一个指向同一个ThreadLocal变量的引用,这些线程依然不能看到 ...

  6. poj 1151(离散化+矩形面积并)

    题目链接:http://poj.org/problem?id=1151 关于离散化,这篇博客讲的很好:http://www.cppblog.com/MiYu/archive/2010/10/15/12 ...

  7. 在Centos中使用goaccess查看Nginx日志

    在Nginx的配置文件中配置一下access日志: log_format access ‘$remote_addr – $remote_user [$time_local] “$request” ‘‘ ...

  8. 来杯咖啡-装饰者模式(Decorator)

    前言 上篇[观察者模式]发布已经近一个月了,个人感觉反应并不太理想,因为大家响应都不是很积极,不知是文章那里写得有问题,而且也没有人提出过有价值的改进建议,多少感觉有些失望L!因为工作繁忙,所以不可能 ...

  9. Linux下配置APUE的编译环境

    APUE即Unix环境高级编程,本书中几乎所有的程序都包含一个apue.h的头文件,那如何配置这个apue.h呢? 1.我们可以在http://pan.baidu.com/s/1dDxmtbF中下载, ...

  10. (3)PHP环境搭建和使用

    一.php开发环境 php开发的环境组件一般需要 apache(iis)+mysql+php 可以自己搭建环境或者用别人把这几项集成好的软件,自己搭建的环境配置起来麻烦但可以选择任意版本,集成的软件安 ...