SGU 123 The sum

求Fibonacci前K项和(0<K<41)

面向大海春暖花开

SGU 123 The sum
/*************************************************************************
    > File Name:    sgu123.cpp
    > Author:       Shine
    > Created Time: 2013-05-06 下午 6:05:51
    > QuestionType: Water
    > Way: 
    > Submit: 
    > Gain: 
    > Experience: 
 ************************************************************************/
#include <cstdio>

int re[50] = {0, 1, 2};
int f[50] = {0, 1, 1};

void predo() {
    int i;
    for (i = 3; i <= 45; i++) {
        f[i] = f[i-1] + f[i-2];
        re[i] = re[i-1] + f[i];
    }
}

int main() {
    predo();
    int k;
    while (~scanf("%d", &k)) {
        printf("%d\n", re[k]);
    }
    return 0;
}

 

posted on 2013-05-06 18:12  ShineCheng  阅读(104)  评论(0编辑  收藏  举报

导航