ZOJ 3702 Gibonacci number
来源:互联网 发布:linux du显示行号 编辑:程序博客网 时间:2024/05/22 12:21
In mathematical terms, the normal sequence F(n) of Fibonacci numbers is defined by the recurrence relation
F(n)=F(n-1)+F(n-2)with seed values
F(0)=1, F(1)=1In this Gibonacci numbers problem, the sequence G(n) is defined similar
G(n)=G(n-1)+G(n-2)with the seed value for G(0) is 1 for any case, and the seed value forG(1) is a random integert, (t>=1). Given thei-th Gibonacci number valueG(i), and the numberj, your task is to output the value forG(j)
Input
There are multiple test cases. The first line of input is an integer T < 10000 indicating the number of test cases. Each test case contains3 integersi, G(i) and j. 1 <= i,j <=20,G(i)<1000000
Output
For each test case, output the value for G(j). If there is no suitable value fort, output -1.
Sample Input
41 1 23 5 43 4 612 17801 19
Sample Output
28-1516847
把每个数拆分成xg1+yg0 g0=1然后就求得g1了
#include <stdio.h>struct pp{ int a0,a1;}a[30];int main(){ a[0].a0=1; a[0].a1=0; a[1].a0=0; a[1].a1=1; for(int i=2;i<=20;i++) { a[i].a0=a[i-1].a0+a[i-2].a0; a[i].a1=a[i-1].a1+a[i-2].a1; } int cas; long long k,l,m,temp; double temp1; scanf("%d",&cas); while(cas--) { scanf("%lld %lld %lld",&k,&m,&l); temp1=(double)(m-a[k].a0)/a[k].a1; if(temp1!=(int)temp1 || temp1<1) { printf("-1\n"); continue; } temp=(long long)temp1; printf("%lld\n",temp*a[l].a1+a[l].a0); } return 0;}
- ZOJ 3702 Gibonacci number
- zoj 3702 Gibonacci number
- ZOJ 3702 Gibonacci number
- zoj 3702 Gibonacci number
- ZOJ 3702 Gibonacci number
- ZOJ 3702 Gibonacci number
- ZOJ 3702 Gibonacci number
- ZOJ 3702 Gibonacci number【思维】
- ZOJ Problem Set - 3702 Gibonacci number
- ZOJ 3702 Gibonacci number 找规律
- ZOJ 3702 Gibonacci number(数学推导题)
- Gibonacci number
- Gibonacci number
- Gibonacci number
- G - Gibonacci number
- Gibonacci number 【斐波拉契】
- Gibonacci number【斐波拉契】
- ZOJ3702-Gibonacci number
- 笔试题:在一个字符串中查找子字符串的个数
- R语言之多元回归实战
- HDU 5299 Circles Game (圆的扫描线+树上SG)
- Robotium 自动化测试
- Java访问控制符:public,private,protected
- ZOJ 3702 Gibonacci number
- IOS navigationItem 设置返回按钮,title图片和rightBarButtonItem
- LDF文件过大,如何收缩
- uva 111 History Grading
- Web系统大规模并发——电商秒杀与抢购
- Algorithms—120.Triangle
- poj1870--Bee Breeding(模拟)
- CF 45C Dancing Lessons(优先队列)
- 二叉树