快速切题 sgu123. The sum

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;

}

  

你可能感兴趣的:(SUM)