ustc_1003_Fibonacci Numbers
来源:互联网 发布:社交网络在线观看 编辑:程序博客网 时间:2024/05/22 16:59
More than Fibonacci
Time Limit: 1000ms
Memory Limit: 65536kb
Memory Limit: 65536kb
Description
The New Fibonacci numbers (0, 1, 2, 3, 6, 11, 20, 37, 68, ...) are defined by the recurrence:F(0) = 0; F(1) = 1; F(2) = 2; F(n) = F(n-1) + F(n-2) + F(n-3) for all n>2Write a program to calculate the New Fibonacci numbers.
Input
The input is a sequence of integers not more than 36, each on a separate line, specifying which New Fibonacci number to calculate.Output
Print the New Fibonacci numbers in the format shown in Sample Output.Sample Input
5711
Sample Output
The New Fibonacci number for 5 is 11The New Fibonacci number for 7 is 37The New Fibonacci number for 11 is 423
很简单的题,注意输出就可以了。。
#include<cstdio>#include<iostream>#include<cstring>using namespace std;int main(){ long long int a,b,c,d; long long int resu; while(cin>>a) {resu=0; if(a==0) cout<<"The New Fibonacci number for 0 is 0"<<endl; else if(a==1) cout<<"The New Fibonacci number for 1 is 1"<<endl; else if(a==2) cout<<"The New Fibonacci number for 2 is 2"<<endl; else if(a>=3) { int temp=a; b=0; c=1; d=2; a=a-2; while(a--) { resu=b+c+d; b=c; c=d; d=resu; } cout<<"The New Fibonacci number for "<<temp<<" is "<<resu<<endl; } } return 0;}
0 0
- ustc_1003_Fibonacci Numbers
- Numbers
- Numbers
- Numbers
- Numbers
- Numbers
- Ugly Numbers
- Humble Numbers
- Humble Numbers
- Palindrom Numbers
- Niven Numbers
- Alien Numbers
- Alien Numbers
- Phone Numbers
- usaco_humble numbers
- Alien Numbers
- Alien Numbers
- hdu1058humble numbers
- configure交叉编译
- linux进程地址空间
- xcode编译后的.app文件
- 关于OpenClinica部署出错的问题汇总(一)
- Objective C--模板方法模式
- ustc_1003_Fibonacci Numbers
- Python里的enumerate
- hibernate criteria 分组 排序 关联
- Manacher算法--O(n)求最长回文串+hdu3068
- 2088 Box of Bricks
- AVS中国标准闯过三重门 一元专利费出台始末
- php学习之道:php中soap的使用实例以及生成WSDL文件,提供自动生成WSDL文件的类库——SoapDiscovery.class.php类
- Positive-definite kernel
- WCF中的ServiceHost初始化两种方式