描述

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的更多相关文章

  1. 算法与数据结构(九) 查找表的顺序查找、折半查找、插值查找以及Fibonacci查找

    今天这篇博客就聊聊几种常见的查找算法,当然本篇博客只是涉及了部分查找算法,接下来的几篇博客中都将会介绍关于查找的相关内容.本篇博客主要介绍查找表的顺序查找.折半查找.插值查找以及Fibonacci查找 ...

  2. #26 fibonacci seqs

    Difficulty: Easy Topic: Fibonacci seqs Write a function which returns the first X fibonacci numbers. ...

  3. 关于java的递归写法,经典的Fibonacci数的问题

    经典的Fibonacci数的问题 主要想展示一下迭代与递归,以及尾递归的三种写法,以及他们各自的时间性能. public class Fibonacci { /*迭代*/ public static ...

  4. 斐波拉契数列(Fibonacci) 的python实现方式

    第一种:利用for循环 利用for循环时,不涉及到函数,但是这种方法对我种小小白来说比较好理解,一涉及到函数就比较抽象了... >>> fibs = [0,1] >>&g ...

  5. fibonacci数列(五种)

    自己没动脑子,大部分内容转自:http://www.jb51.net/article/37286.htm 斐波拉契数列,看起来好像谁都会写,不过它写的方式却有好多种,不管用不用的上,先留下来再说. 1 ...

  6. POJ3070 Fibonacci[矩阵乘法]

    Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13677   Accepted: 9697 Descri ...

  7. Fibonacci 数列算法分析

    /************************************************* * Fibonacci 数列算法分析 ****************************** ...

  8. 算法系列:Fibonacci

    Copyright © 1900-2016, NORYES, All Rights Reserved. http://www.cnblogs.com/noryes/ 欢迎转载,请保留此版权声明. -- ...

  9. UVa #11582 Colossal Fibonacci Numbers!

    巨大的斐波那契数 The i'th Fibonacci number f (i) is recursively defined in the following way: f (0) = 0 and  ...

  10. Buge's Fibonacci Number Problem

    Buge's Fibonacci Number Problem Description snowingsea is having Buge’s discrete mathematics lesson, ...

随机推荐

  1. 手机看youtube的方法|一个好用的VPN

    俗话说:网络无国界.但是由于天朝的限制,我们无法访问YouTube .谷歌.twitter等一些国外网站. 这个时候我们就需要FQ.最直接有效的方法就是:VPN(虚拟专用网络). 虚拟专用网络的功能是 ...

  2. JavaScript学习笔记(13)——BOM

    1.window 所有浏览器都支持window对象,它表示浏览器窗口本身. 所有 JavaScript 全局对象.函数以及变量均自动成为 window 对象的成员. 全局变量是 window 对象的属 ...

  3. (POJ 3694) Network 求桥个数

    题目链接:http://poj.org/problem?id=3694Description A network administrator manages a large network. The ...

  4. Contest1065 - 第四届“图灵杯”NEUQ-ACM程序设计竞赛(个人赛)A蔡老板的会议

    题目描述 图灵杯个人赛就要开始了,蔡老板召集俱乐部各部门的部长开会.综合楼有N (1<=N<=1000)间办公室,编号1~N每个办公室有一个部长在工(mo)作(yu),其中X号是蔡老板的办 ...

  5. 修改SSH端口为21

    在交流群里面有一位兄弟问到能否将ssh端口号修改为21端口,后来经过测试可以设置,具体步骤如下: 一.修改ssh配置文件的默认端口 #vim /etc/ssh/sshd_config 找到#port ...

  6. 多项分布(multinominal distribution)

    简介 更一般性的问题会问:“点数1~6的出现次数分别为(x1,x2,x3,x4,x5,x6)时的概率是多少?其中sum(x1~x6)= n”.这就是一个多项式分布. 定义 把二项分布推广至多个(大于2 ...

  7. input内容改变触发事件,兼容IE

    <html> <head> <script type="text/javascript"> window.onload = function() ...

  8. Ubuntu的默认root密码

    Ubuntu的默认root密码是随机的,即每次开机都有一个新的root密码.我们可以在终端输入命令 sudo passwd,然后输入当前用户的密码,enter,终端会提示我们输入新的密码并确认,此时的 ...

  9. Hibernate 老外的完整教程

    http://viralpatel.net/blogs/hibernate-many-to-many-annotation-mapping-tutorial/

  10. spring-cloud-feign案例

    主要依赖 <dependencyManagement> <dependencies> <dependency> <groupId>org.springf ...