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, ...
随机推荐
- Oracle中存储过程传入表名学习
Oracle中存储过程传入表名: 一.动态清除该表的数据 create or replace procedure p_deletetable(i_tableName in varchar2) as ...
- 在swift中使用MJRefresh
cocoapod导入的,并且桥接已经完成,但是就是不提示方法,醉了,
- Linux 文件系统 相关
鸟个讲得很详细啦:http://vbird.dic.ksu.edu.tw/linux_basic/0230filesystem_1.php 重要知识点:磁盘,文件系统,超级区块 (superblock ...
- javascript-对象的创建(一)
<!DOCTYPE html> <%@ page language="java" contentType="text/html; charset=UTF ...
- 个人站长如何使用svn发布到服务器不遗漏文件
作为个人站长,最最头疼的一件事情就是在本地开发好代码之后,上传的时候要去服务器上一个一个文件进行覆盖,添加操作:是人难免出错,避免这种情况的方法: 开发者最好是在本地有一个代码库,创建好代码库之后,至 ...
- 【转】sqlserver查询数据库中有多少个表
sql server 数表: select count(1) from sysobjects where xtype='U' 数视图: select count(1) from sysobjects ...
- phpcms v9 源码解析- 2 base.php
base.php在上文已经说过,是在PC中重要的一个文件,基本常量.核心类文件的加载都由它来完成. 9行,定义了一个常量 IN_PHPCMS,在系统的入口定义一个常量,在其他文件就判断是否这个常量被定 ...
- 开始学习python
刚刚离开学校,到公司实习,发现所有的技术都是崭新的,所有的工具都是熟悉中带着陌生. 就像是孤身一人到了一个曾经只闻其名的偌大城市,看什么都觉得新鲜,做什么都心有畏惧.幸好 搞软件并没有那么多人情世故, ...
- Palindromic Number (还是大数)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- 实现c++的string的split功能
今天写程序,遇到了一个要实现string.split()这个的一个函数.python里面有,qt里面有,c++里面没有.照着网上抄了一个,放在这里.有需要的时候直接拽过去用,否则老是写了小例子就扔,用 ...