Fibbonacci Number

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 22530    Accepted Submission(s): 10375

Problem Description
Your objective for this question is to develop a program which will generate a fibbonacci number. The fibbonacci function is defined as such:

f(0) = 0
f(1) = 1
f(n) = f(n-1) + f(n-2)

Your program should be able to handle values of n in the range 0 to 50.
 

Input
Each test case consists of one integer n in a single line where 0≤n≤50. The input is terminated by -1.
 

Output
Print out the answer in a single line for each test case.
 

Sample Input
3
4
5
-1
 

Sample Output
2
3
5
Hint
Note:

you can use 64bit integer: __int64

费波纳列数

#include <iostream>
using namespace std; const int limit = 51;
_int64 fib[limit]; int main()
{
int num;
fib[0] = 0;
fib[1] = 1;
for (int i = 2; i <= limit; i++)
{
fib[i] = fib[i - 1] + fib[i - 2];
} while (cin >> num && num!=-1)
{
cout << fib[num] << endl;
}
return 0;
}

最新文章

  1. c# HttpClient禁止缓存
  2. js字符串RTrim方法(right trim)
  3. windows下关闭80端口被system占用的情况
  4. charles使用教程指南(抓包工具)
  5. ORACLE 常用数值函数
  6. oracle误删除恢复
  7. Python还是很重要的,不能丢。学习IF和WHILE
  8. JAVA获得系统配置文件的System Properties
  9. Sql Server 2008/2005 数据库还原出现 3154错误
  10. 【luogu P1396】营救
  11. 空间搜索(圆范围)中Geohash编码方案和网格编码方案对比探讨
  12. C#连接Access数据库
  13. Docker: 创建带数据的MySql container
  14. 教你一个vue小技巧,一般人我不说的
  15. PHP策略模式demo
  16. VMware 虚拟机CentOS 7 网路连接配置 无eth0简单解决办法
  17. [leetcode]Word Search @ Python
  18. Linux Kernel sys_call_table、Kernel Symbols Export Table Generation Principle、Difference Between System Calls Entrance In 32bit、64bit Linux【转】
  19. 23LINQ运算符返回其它类型实例汇总
  20. [3D]1.绘制三角形

热门文章

  1. python基础一 ------如何根据字典值对字典进行&quot;排序&quot;
  2. Android应用的内存管理
  3. BZOJ4739 : 定向越野
  4. vb.net播放资源文件中的音乐
  5. 道路 [NOIP模拟]
  6. numpy快速入门
  7. http理解
  8. Amazon Publisher Studio让产品推广更简单
  9. Go web编程实例
  10. linux go环境安装和基本项目结构