斐波那契?
来源:互联网 发布:时时彩做计划软件 编辑:程序博客网 时间:2024/05/16 08:30
斐波那契?
Time Limit: 1000MS Memory Limit: 32768KB
Submit Statistic
Problem Description
给出一个数列的递推公式,希望你能计算出该数列的第N个数。递推公式如下:
F(n)=F(n-1)+F(n-2)-F(n-3). 其中,F(1)=2, F(2)=3, F(3)=5.
很熟悉吧,可它貌似真的不是斐波那契数列呢,你能计算出来吗?
Input
输入只有一个正整数N(N>=4).
Output
输出只有一个整数F(N).
Example Input
5
Example Output
8
Hint
Author
#include<stdio.h>#include<stdlib.h>int f(int n){ if(n==1)return 2; else if(n==2)return 3; else if(n==3)return 5; else return f(n-1)+f(n-2)-f(n-3);}int main(){ int n; scanf("%d",&n); printf("%d\n",f(n)); return 0;}
阅读全文
0 0
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 【斐波那契】
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 【Android】WebView链接为https,内容图片为http,图片不显示
- 确保对象的唯一性——单例模式 (四)
- python学习—Day16—类(一般形式、继承)
- 一整数数组,将奇数放在前面,偶数放在后面
- 红黑树
- 斐波那契?
- uva10608
- ArrayList解析
- Python FTP
- DecimalFormat
- Android RxJava 实战讲解:优雅实现 网络请求轮询
- 引用类型与垃圾回收
- springmvc log4j设置日志输出级别
- NYOJ 364 HDU 1052 田忌赛马