1962-Fibonacci
描述
This is an easy problem.I think Fibonacci sequence is familiar to you.Now there is another one.

Here a and b are constants.Gice you a,b,and n,your task is to calculate the f[n].
输入
First line of input comes a positive integer T(T<=10) indicating the number of test cases.Each test case contains three positive integer a,b and n(a<=10,b<=10,n<=30)
输出
Print one line containing an integer,i.e.f[n],for each test case.
样例输入
2
1 2 3
1 3 6
样例输出
3
24
#include<iostream>
using namespace std; int main()
{
int m,a,b,n,t;
int sum=0;
cin>>m;
while(m--)
{
cin>>a>>b>>n;
if(n==1) cout<<a<<endl;
else if(n==2) cout<<b<<endl;
else{
for(int i=3;i<=n;i++)
{
if(i%2==1) t=a+b;
else
{
t=a+a+b+b;
a=b+a;
b=t;
}
}
cout<<t<<endl;
}
}
return 0;
}
1962-Fibonacci的更多相关文章
- 算法与数据结构(九) 查找表的顺序查找、折半查找、插值查找以及Fibonacci查找
今天这篇博客就聊聊几种常见的查找算法,当然本篇博客只是涉及了部分查找算法,接下来的几篇博客中都将会介绍关于查找的相关内容.本篇博客主要介绍查找表的顺序查找.折半查找.插值查找以及Fibonacci查找 ...
- #26 fibonacci seqs
Difficulty: Easy Topic: Fibonacci seqs Write a function which returns the first X fibonacci numbers. ...
- 关于java的递归写法,经典的Fibonacci数的问题
经典的Fibonacci数的问题 主要想展示一下迭代与递归,以及尾递归的三种写法,以及他们各自的时间性能. public class Fibonacci { /*迭代*/ public static ...
- 斐波拉契数列(Fibonacci) 的python实现方式
第一种:利用for循环 利用for循环时,不涉及到函数,但是这种方法对我种小小白来说比较好理解,一涉及到函数就比较抽象了... >>> fibs = [0,1] >>&g ...
- fibonacci数列(五种)
自己没动脑子,大部分内容转自:http://www.jb51.net/article/37286.htm 斐波拉契数列,看起来好像谁都会写,不过它写的方式却有好多种,不管用不用的上,先留下来再说. 1 ...
- POJ3070 Fibonacci[矩阵乘法]
Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13677 Accepted: 9697 Descri ...
- Fibonacci 数列算法分析
/************************************************* * Fibonacci 数列算法分析 ****************************** ...
- 算法系列:Fibonacci
Copyright © 1900-2016, NORYES, All Rights Reserved. http://www.cnblogs.com/noryes/ 欢迎转载,请保留此版权声明. -- ...
- UVa #11582 Colossal Fibonacci Numbers!
巨大的斐波那契数 The i'th Fibonacci number f (i) is recursively defined in the following way: f (0) = 0 and ...
- Buge's Fibonacci Number Problem
Buge's Fibonacci Number Problem Description snowingsea is having Buge’s discrete mathematics lesson, ...
随机推荐
- 注意java的对象引用
要注意,当前拿到的“对象引用”, 是不是 指向 最新的实例, 没有的话, 要重新 生成实例去指向. 代码例子: AnsweringRuleInfo bhRule = accountGenerator. ...
- Query 快速入门教程
Query 快速入门教程 http://www.365mini.com/page/jquery-quickstart.htm#what_is_jquery jquery常用方法及使用示例汇总 http ...
- UGUI之在场景中设置、修改标签和按钮
UnityGUI使用一个特殊的OnGUI()函数,在该函数中加入实现UI的脚本. 它一共有两种类型的接口:GUI.xxx()和GUILayout.xxx(). 第一种需要自动手写填写处于屏幕上的位置. ...
- Sublime Text 破解
引言 放假三天,呆家里把win7换成了win8.1,接着玩起了hyperv,试着装了个windows xp虚拟机,体验很不错.不过对linux系统的支持不怎么样,装了个ubuntu,体验相当差!闲着无 ...
- 使用轻量级Spring @Scheduled注解执行定时任务
WEB项目中需要加入一个定时执行任务,可以使用Quartz来实现,由于项目就一个定时任务,所以想简单点,不用去配置那些Quartz的配置文件,所以就采用了Spring @Scheduled注解来实现了 ...
- 关于linux下零散的东西 --慢慢补充
一.截图 ,使用Shift+Ctrl+PrtSc就可以截图. 二.tar命令参数 c:表示压缩 x:表示解压 z:表示gzip的方式解/压缩 j:表示bzip2的方式解/压缩 三.串口终端ke ...
- nginx源码分析
ngx_init_cycle 解析配置文件 完成模块中command set函数调用
- 在Windows下设置环境变量 运行mysql程序变得更容易
在Windows下设置环境变量,点开始菜单,右键单击我的电脑--属性--高级--环境变量 可以看到PATH的变量是这样的: C:\WINDOWS;C:\WINDOWS\COMMAND 为了让运行m ...
- CocoaPods安装和使用及问题:Setting up CocoaPods master repo
CocoaPods是什么? 当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONKit,AFNetWorking等等.可能某个类库又用到其他类库,所以要使用它,必须得另外下载其他类库,而 ...
- JS禁用和启用鼠标滚轮滚动事件
// left: 37, up: 38, right: 39, down: 40, // spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: ...