SGU - 123 - The sum (简单数学!)

SGU - 123
Time Limit: 250MS Memory Limit: 4096KB 64bit IO Format: %I64d & %I64u

 Status

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 K Nacci numbers.

 

Input

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

 

Output

First line should contain number S.

 

Sample Input

5

 

Sample Output

12

Source




简单数学求和题,,居然int都不会爆,,刚开始我还以为要long long。。


AC代码:


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;

int a[42] = {0,1,1};

int main()
{
	int k;
	for(int i=3; i<41; i++)
	{
		a[i] = a[i-1] + a[i-2];
	}	
	scanf("%d", &k);
	int ans = 0;
	for(int i=1; i<=k; i++)
	{
		ans += a[i];
	}
	printf("%d\n", ans);
	return 0;
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值