HUNAN 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 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(爆力枚举)的更多相关文章
- 【扩展欧几里得】BAPC2014 I Interesting Integers (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- interesting Integers(数学暴力||数论扩展欧几里得)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAwwAAAHwCAIAAACE0n9nAAAgAElEQVR4nOydfUBT1f/Hbw9202m0r8
- GYM100526I Interesting Integers
题目大意 定义一种 \(Gabonacci\) 数列: \[\begin{array}{c} G_1=a\\ G_2=b\\ G_i=G_{i-1}+G_{i-2} \end{array} \] 给定 ...
- 计蒜客 28319.Interesting Integers-类似斐波那契数列-递推思维题 (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 I)
I. Interesting Integers 传送门 应该是叫思维题吧,反正敲一下脑壳才知道自己哪里写错了.要敢于暴力. 这个题的题意就是给你一个数,让你逆推出递推的最开始的两个数(假设一开始的两个 ...
- Google kickstart 2022 Round A题解
Speed Typing 题意概述 给出两个字符串I和P,问能否通过删除P中若干个字符得到I?如果能的话,需要删除字符的个数是多少? 数据规模 \[1≤|I|,|P|≤10^5 \] 双指针 设置两个 ...
- 解剖SQLSERVER 第十七篇 使用 OrcaMDF Corruptor 故意损坏数据库(译)
解剖SQLSERVER 第十七篇 使用 OrcaMDF Corruptor 故意损坏数据库(译) http://improve.dk/corrupting-databases-purpose-usin ...
- 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 ...
- ACM 第十七天
暑期热身赛 BAPC 2014 The 2014 Benelux Algorithm Programming Contest 题目网址:https://odzkskevi.qnssl.com/3655 ...
- Benelux Algorithm Programming Contest 2014 Final
// Button Bashing (bfs) 1 #include <iostream> #include <cstdio> #include <cstring> ...
随机推荐
- web项目报outmemory错误解决方案
因为数据问题内存不够出现错误,将参数加入到eclipse的run的配置文件中:
- noi2017 T1 整数 ——线段树
loj.ac上有 题目传送门 不过我还是把题目搬过来吧 整数(integer)[题目背景]在人类智慧的山巅,有着一台字长为 1048576 位的超级计算机,著名理论计算机科 学家 P 博士正用它进行 ...
- 杭电oj2032、2040、2042、2054、2055
2032 杨辉三角 #include <stdio.h> int main(){ ][],i,j,n; while(~scanf("%d",&n)){ ;i& ...
- Mysql 连接池
数据库连接池的作用: 数据库连接池负责分配.管理和释放数据库连接,它允许应用程序重复使用一个现有的数据库连接,而不是再重新建立一个:释放空闲时间超过最大空闲时间的数据库连接来避免因为没有释放数据库连接 ...
- Appium+python自动化3-启动淘宝app【转载】
前言 前面两篇环境已经搭建好了,接下来就是需要启动APP,如何启动app呢?首先要获取包名,然后获取launcherActivity.获取这两个关键东西的方法很多,这里就不一一多说,小伙伴们可以各显神 ...
- 读取EXCEL的办法
private void button9_Click(object sender, EventArgs e) { var folder =new FolderBrowserDialog(); if ( ...
- superviosrd进程管理
supervisor进程管理器---------------------------1. 安装依赖yum install python-setuptools-devel 2. 安装supervisor ...
- UBIFS分区制作及UBIFS烧写和启动
参考 http://blog.csdn.net/chongzi865458/article/details/6799258 ubiattach version 1.0 - a tool to atta ...
- Volley缓存说明——一个请求两次回调
从上一篇文章Android 异步网络请求框架-Volley了解volley的一些出来过程,当然也包含网络请求和缓存处理的流程,但是在此需要单独做一些说明. 我在使用过程中忽略了一个事情,就是一个网络请 ...
- docker之人手一台服务器
安装docker uname –r 检查内核版本 yum update 升级本地yum包 vim /etc/yum.repos.d/docker.repo #添加yum仓库配置 [dockerrepo ...