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. 最好的10个移动 Web 应用程序开发框架

    在近期几年里,移动互联网快速发展.市场潜力巨大. 继计算机.互联网之后,移动互联网正掀起第三次信息技术革命的浪潮,新技术.新应用不断涌现.今天这篇文章向大家推荐10大优秀的移动Web开发框架.帮助开发 ...

  2. java性能监控工具jstat-windows

    jstat Monitors Java Virtual Machine (JVM) statistics. This command is experimental and unsupported. ...

  3. Laravel 设置语言不生效的问题

    使用了validate 验证,提示错误默认是 英文的.将en 改为zh-CN 后 运行 composer require "overtrue/laravel-lang:~3.0"时 ...

  4. python(25)- 面向对象补充Ⅰ

    一.如何使用类 1.实例化:创建对象 类名加括号就是实例化,会自动触发__init__函数的运行,可以用它来为每个实例定制自己的特征. 例子一 x=int(10) print(x) python中一切 ...

  5. 为什么应使用 Node.js

    为什么应使用 Node.js JavaScript 高涨的人气带来了很多变化,以至于如今使用其进行网络开发的形式也变得截然不同了.就如同在浏览器中一样,现在我们也可以在服务器上运行 JavaScrip ...

  6. openshifit 安装 redis

    http://blog.csdn.net/lsx991947534/article/details/48860537 http://blog.csdn.net/aguangg_6655_la/arti ...

  7. kubernetes 之QoS服务质量管理

    系列目录 在kubernetes中,每个POD都有个QoS标记,通过这个Qos标记来对POD进行服务质量管理.QoS的英文全称为"Quality of Service",中文名为& ...

  8. Centos7-搭建hdfs启动时报java.net.BindException: Problem binding to [node01:9000] java.net.BindException异常

    今天用阿里的服务器搭了个伪分布式的HDFS,格式化后启动hdfs,发现只有dataNode启动了,查看启动日志发现异常: 2019-01-22 15:54:50,507 FATAL org.apach ...

  9. MacOS 修改主机名

    修改主机名 sudo scutil --set HostName xxx 修改共享名 sudo scutil --set ComputerName xxx

  10. linux的su和sudo(转载)

    来源:http://www.jb51.net/LINUXjishu/12713.html 一. 使用 su 命令临时切换用户身份 1.su 的适用条件和威力 su命令就是切换用户的工具,怎么理解呢?比 ...