暑假集训#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从未如此简单
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值