ZOJ 3702 Gibonacci number
来源:互联网 发布:mindmanager注册机mac 编辑:程序博客网 时间:2024/05/22 14:27
Description
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 for G(1) is a random integer t, (t>=1). Given the i-th Gibonacci number value G(i), and the number j, your task is to output the value for G(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 contains 3integers i, 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 for t, output -1.
Sample Input
41 1 23 5 43 4 612 17801 19
Sample Output
28-1516847
先求出t再算,注意t>=1
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;const int maxn=21;int f[maxn][2],a,b,c;int main(){f[0][0]=f[1][1]=1;f[0][1]=f[1][0]=0;for (int i=2;i<maxn;i++){f[i][0]=f[i-1][0]+f[i-2][0];f[i][1]=f[i-1][1]+f[i-2][1];}int T;scanf("%d",&T);while (T--){scanf("%d%d%d",&a,&b,&c);if ((b-f[a][0])%f[a][1]||b<=f[a][0]) printf("-1\n");else {long long d[maxn];d[0]=1;d[1]=(b-f[a][0])/f[a][1];for (int i=2;i<=c;i++) d[i]=d[i-1]+d[i-2];cout<<d[c]<<endl;}}}
- 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
- Android桌面弹窗实现总结
- Android彻底退出应用程序
- Fragement
- 语言与模式-21解释器模式
- 推荐30个国外的精美字体下载网站
- ZOJ 3702 Gibonacci number
- Docker学习笔记 — Docker镜像
- Unity3d学习记录(一)摄像机跟随人物移动,并且注视人物
- DFS,拓扑排序
- 自学java语法笔记总结02
- ThreadLocal-分析-总结
- 新的开始
- hadoop下mahout bayes(贝叶斯)算法研究(2)
- poj 3159 Candies