123. The sum

time limit per test: 0.25 sec. 
memory limit per test: 4096 KB

The Fibonacci sequence of numbers is known: F1 = 1; F2 = 1; Fn+1 = Fn + Fn-1, for n>1. You have to find S - the sum of the first K Fibonacci numbers.

Input

First line contains natural number K (0<K<41).

Output

First line should contain number S.

Sample Input

5

Sample Output

12
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=41;
long long f[maxn];
int main(){
int k;long long s=1;
scanf("%d",&k);f[1]=1;
for(int i=2;i<=k;i++){
f[i]=f[i-1]+f[i-2];
s+=f[i];
}
printf("%I64d\n",s);
return 0;
}

  

快速切题 sgu123. The sum的更多相关文章

  1. 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum

    Sum Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...

  2. 快速切题sgu126. Boxes

    126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...

  3. 快速切题 sgu118. Digital Root 秦九韶公式

    118. Digital Root time limit per test: 0.25 sec. memory limit per test: 4096 KB Let f(n) be a sum of ...

  4. 快速切题 sgu116. Index of super-prime bfs+树思想

    116. Index of super-prime time limit per test: 0.25 sec. memory limit per test: 4096 KB Let P1, P2, ...

  5. 快速切题 sgu104. Little shop of flowers DP 难度:0

    104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB PROBLEM Yo ...

  6. 快速切题 acdream手速赛(6)A-C

    Sudoku Checker Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Submi ...

  7. 快速切题 poj1258

    坑!!!我还以为一个整数会截到两行!! Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 40056   Ac ...

  8. 快速切题 sgu134.Centroid 树形dp

    134. Centroid time limit per test: 0.25 sec. memory limit per test: 4096 KB You are given an undirec ...

  9. 快速切题 poj 1003 hangover 数学观察 难度:0

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 103896   Accepted: 50542 Descr ...

随机推荐

  1. hdu 3336 Count the string -KMP&dp

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

  2. assert函数用法总结【转】

    本文转载自:http://blog.csdn.net/u014082714/article/details/45190505 assert宏的原型定义在<assert.h>中,其作用是如果 ...

  3. Spring通过ApplicationContext主动获取bean

    有些场景无法通过AutoWired和compoment注解传递进来,于是希望通过Spring context主动去获取beandemo: package com.qhong.Util; import ...

  4. UVA 11806 Cheerleaders (容斥原理

    1.题意描述 本题大致意思是讲:给定一个广场,把它分为M行N列的正方形小框.现在给定有K个拉拉队员,每一个拉拉队员需要站在小框内进行表演.但是表演过程中有如下要求: (1)每一个小框只能站立一个拉拉队 ...

  5. iis发布,部署

    1.项目发布:选择iis:文件系统:文件路径:realese 2.iis添加: 3.host文件添加 问题1: 不能在此路径中使用此配置节.如果在父级别上锁定了该节,便会出现这种情况.锁定 在全新安装 ...

  6. Goroutines和Channels(一)

    Go语言中的并发程序可以用两种手段来实现.本章讲解goroutine和channel,其支持“顺序通信进程”(communicating sequential processes)或被简称为CSP.C ...

  7. shell case语句

    case 格式 case 值 in 模式1) command1 command2 ... commandN ;; 模式2) command1 command2 ... commandN ;; esac ...

  8. 软件测试实习生 带人计划 Plan for Training Inten

    临时拟了个提纲,以后慢慢补充吧 序号 培训内容 时间安排 1 根据项目需求,编写测试用例,针对存储过程 2 存储过程的走读,以及怎样执行测试用例和查看结果 3 根据项目需求,编写测试用例,针对接口[C ...

  9. MongoDB(课时16 分页显示)

    3.4.2.11 数据分页显示 在MongoDB里面的数据分页显示也是符合于大数据要求的操作函数: skip(n):表示跨过多少数据行 limit(n):取出的数据行的个数限制 范例:分页显示(比如显 ...

  10. Qt4_WebKit_例子

    1. 安装包:qt-opensource-windows-x86-vs2010-4.8.6.exe Qt4已经编译好的文件:E:\ZC_software_installDir\Qt_4.8.6\dem ...