Gibonacci number-斐波那契数列
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 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
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-斐波那契数列的更多相关文章
- hdu number number number 斐波那契数列 思维
http://acm.hdu.edu.cn/showproblem.php?pid=6198 F0=0,F1=1的斐波那契数列. 给定K,问最小的不能被k个数组合而成的数是什么. 赛后才突然醒悟,只要 ...
- 509. Fibonacci Number斐波那契数列
网址:https://leetcode.com/problems/fibonacci-number/ 原始的斐波那契数列 运用自底向上的动态规划最佳! 可以定义vector数组,但是占用较多内存空间 ...
- 【LeetCode每天一题】Fibonacci Number(斐波那契数列)
The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such th ...
- 剑指offer--4.斐波那契数列
int最大范围(有符号情况下,从第0项0开始)能取到第46项1836311903,47项溢出 时间限制:1秒 空间限制:32768K 热度指数:473928 题目描述 大家都知道斐波那契数列,现在要求 ...
- 《BI那点儿事》Microsoft 时序算法——验证神奇的斐波那契数列
斐波那契数列指的是这样一个数列 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10 ...
- 斐波那契数列(fabnacci)java实现
斐波那契数列定义:From Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/Fibonacci_number In math ...
- Javascript数组求和的方法总结 以及由斐波那契数列得到的启发
一次面试中,面试官要求用三种不同的Javascript方法进行一个数字数组的求和,当时思来想去只想到了使用循环这一种笨方法,因此面试比较失败,在这里总结了六种Javascript进行数组求和的方法,以 ...
- 斐波那契数列 Library
http://acm.tju.edu.cn/toj/showp3267.html3267. Library Time Limit: 1.0 Seconds Memory Limit: 6553 ...
- Python 斐波那契数列练习
# coding=gbk # 迭代法---1 def fibonacci (n): if n == 0 or n == 1: return n else : a = 0 b = 1 for i in ...
- 斐波那契数列(C#)
斐波那契数,亦称之为斐波那契数列(意大利语: Successione di Fibonacci),又称黄金分割数列.费波那西数列.费波拿契数.费氏数列,指的是这样一个数列:1.1.2.3.5.8.13 ...
随机推荐
- [Javascript] Await a JavaScript Promise in an async Function with the await Operator
The await operator is used to wait for a promise to settle. It pauses the execution of an async func ...
- xterm.js 基于websocket 链接容器 命令行工具
<template> <div> <el-dialog title="命令" :visible.sync="dialogTableVisib ...
- react-redux的connect()方法
容器组件使用 connect() 方法连接 Redux 我们用 react-redux 提供的 connect() 方法将“笨拙”的 Counter 转化成容器组件.connect() 允许你从 Re ...
- Spring的Scheme位置
org.springframework.aop.config org.springframework.contex.config org.springframework.ejb.config org. ...
- 8款精美的HTML5图片动画分享
From:http://geek.csdn.net/news/detail/196250 HTML5结合jQuery可以让网页图片变得更加绚丽多彩,比如实现一些图片3D切换.CSS3动画绘制以及各种图 ...
- Django-wsgi实例
wsgiref实现了wsgi,他会将复杂的http请求经过处理,得到Django需要的格式,可以说他是一个接口,一端传入数据,一端处理数据 传统的socket实现 import socket def ...
- 在Fedora 23上安装多媒体解码器
在Fedora 23上安装多媒体解码器 时间:2016-06-25来源:topspeedsnail.com 作者:斗大的熊猫 安装多媒体解码器允许你播放更多格式的音频和视频格式.大多数这些解码器都 ...
- php时间12小时和24小时区别
date('Y-m-d H:i:s',$row1['time']) 大写H为24小时制 小写h为12小时制
- 基于UDP的一对回射客户/服务器程序
前言 之前曾经学习过一对回射客户/服务器程序的例子,不过那个是基于TCP协议的.本文将讲解另一对回射客户/服务器程序,该程序基于UDP协议.由于使用的协议不同,因此编写出的程序也有本质上的区别,应将它 ...
- 第 1 章 第 1 题 高级语言的排序问题 C++标准算法实现
问题分析 依题意,所需程序不用过多考虑效率且暗示使用库,自然想到用高级语言实现(个人选择C++).可用顺序容器暂存数据,用标准算法解决排序问题. 代码实现 #include <iostream& ...