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)=1

In 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 iG(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

4
1 1 2
3 5 4
3 4 6
12 17801 19

Sample Output

2
8
-1
516847
 #include"iostream"
#include"algorithm"
#include"cstring"
#include"queue"
#include"cmath"
#include"cstdio"
#include"cstdlib"
using namespace std;
#define sr(x) scanf("%d",&x)
#define sc(x) printf("%d",x)
#define hh printf("\n")
int main()
{
long long f[],x,y,g,z=-,i;
f[]=;f[]=;
for(i=;i<;i++)f[i]=f[i-]+f[i-];
int tt;
cin>>tt;
while(tt--)
{
cin>>x>>g>>y;
if(x>)
{
if((g-f[x-])%f[x-]==)z=(g-f[x-])/f[x-];
else {cout<<-<<endl;continue;}
}
else
{
if(x==)z=g;
else {cout<<-<<endl;continue;}
}
if(z<){cout<<-<<endl;continue;}
if(y==)cout<<<<endl;
else if(y==)cout<<z<<endl;
else cout<<f[y-]+f[y-]*z<<endl;
}
return ;
}

Gibonacci number-斐波那契数列的更多相关文章

  1. hdu number number number 斐波那契数列 思维

    http://acm.hdu.edu.cn/showproblem.php?pid=6198 F0=0,F1=1的斐波那契数列. 给定K,问最小的不能被k个数组合而成的数是什么. 赛后才突然醒悟,只要 ...

  2. 509. Fibonacci Number斐波那契数列

    网址:https://leetcode.com/problems/fibonacci-number/ 原始的斐波那契数列 运用自底向上的动态规划最佳! 可以定义vector数组,但是占用较多内存空间 ...

  3. 【LeetCode每天一题】Fibonacci Number(斐波那契数列)

    The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such th ...

  4. 剑指offer--4.斐波那契数列

    int最大范围(有符号情况下,从第0项0开始)能取到第46项1836311903,47项溢出 时间限制:1秒 空间限制:32768K 热度指数:473928 题目描述 大家都知道斐波那契数列,现在要求 ...

  5. 《BI那点儿事》Microsoft 时序算法——验证神奇的斐波那契数列

    斐波那契数列指的是这样一个数列 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10 ...

  6. 斐波那契数列(fabnacci)java实现

    斐波那契数列定义:From Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/Fibonacci_number In math ...

  7. Javascript数组求和的方法总结 以及由斐波那契数列得到的启发

    一次面试中,面试官要求用三种不同的Javascript方法进行一个数字数组的求和,当时思来想去只想到了使用循环这一种笨方法,因此面试比较失败,在这里总结了六种Javascript进行数组求和的方法,以 ...

  8. 斐波那契数列 Library

    http://acm.tju.edu.cn/toj/showp3267.html3267.   Library Time Limit: 1.0 Seconds   Memory Limit: 6553 ...

  9. Python 斐波那契数列练习

    # coding=gbk # 迭代法---1 def fibonacci (n): if n == 0 or n == 1: return n else : a = 0 b = 1 for i in ...

  10. 斐波那契数列(C#)

    斐波那契数,亦称之为斐波那契数列(意大利语: Successione di Fibonacci),又称黄金分割数列.费波那西数列.费波拿契数.费氏数列,指的是这样一个数列:1.1.2.3.5.8.13 ...

随机推荐

  1. 微信小程序制作商 业务流程

  2. redis cmd 使用样例

    Redis 命令參考 一 Redis介绍 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15 ...

  3. Kubernetes对象之Service

    系列目录 通过ReplicaSet来创建一组Pod来提供具有高可用性的服务.虽然每个Pod都会分配一个单独的Pod IP,然而却存在如下两问题: Pod IP仅仅是集群内可见的虚拟IP,外部无法访问. ...

  4. Ubuntu 16.04 引导修复(Boot Repair)----lianwang----anzhuang windows hou(双系统修复一)

    2016-01-26 20:54 12548人阅读 评论(1) 收藏 举报 分类: =======学习心得=======(23) 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] ...

  5. Android 四大组件学习之BroadcastReceiver一

    本节课学习四大组件最后一个, 广播接受者. 顾名思义广播接受者就是接受广播呗.比方在现实社会中,曾经每一个人家都有一台收音机,这可就能够去接受广播发出来的消息.大家都知道.程序世界也是參照的显示生活设 ...

  6. 51NOD 1810 连续区间 分治 区间计数

    1810 连续区间 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 80     区间内所有元素排序后,任意相邻两个元素值差为1的区间称为“连续区间” 如:3,1,2是连续区间,但3, ...

  7. 2018.11.20-day22 类中代码的执行顺序&组合

    1.类中代码的执行顺序 2.组合

  8. delphi android 录像(使用了JMediaRecorder,MediaRecorder的使用方法)

    delphi xe系列自带的控件都无法保存录像,经网友帮忙,昨天终于实现了录像功能(但有个问题是录像时无画面显示),程序主要使用了JMediaRecorder,MediaRecorder的使用方法可参 ...

  9. mongodb学习之:条件操作符

    在前面的章节中我们已经有用到了条件操作符,这里我们再重点介绍下.MongoDB中条件操作符有: (>) 大于 - $gt (<) 小于 - $lt (>=) 大于等于 - $gte ...

  10. mongodb学习之:文档操作

    在上一章中有讲到文档的插入操作是用insert的方法.如果该集合不在该数据库中,mongodb会自动创建该集合并插入文档 用find的方法可以查找所有的集合数据 > db.maple.find( ...