暑假集训#1 A题

A - A

Crawling in process...Crawling failedTime Limit:500MS    Memory Limit:4096KB     64bit IO Format:%I64d & %I64u

 

Description

Here is your second problem, keep calm and solve it .

Nacci sequence of numbers is known to all : F1 = 1; F2 = 1;Fn+1 =Fn + Fn-1, for n>1.You have to find S - the sum of the first KNacci 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<iostream>
#include<stdio.h>
using namespace std; 
int main()
{
	int k;
	while(cin>>k)
	{
		int t1=1,t2=1,t3;
		int sum=0;
		if(k==1)
		{
			sum=1;
		}
		else if(k==2)
		{
			sum=2;
		}
		else
		{
			sum=2;
			for(int i=3;i<=k;i++)
		  {
			t3=t1+t2;
			sum+=t3;
			t1=t2;
			t2=t3;
		  }
		}
		cout<<sum<<endl;
	}
}
//我真心的希望以后集训不要出现类似的水题,这只会让人错误的认为原来acm是如此简单,但事实是acm从未如此简单
posted @ 2013-07-28 00:20  湖心北斗  阅读(113)  评论(0编辑  收藏  举报