首页 > 其他 > 详细

入门训练 Fibonacci数列

时间:2018-09-23 12:32:05      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:ron   +=   using   names   ++   void   sin   span   !=   

http://lx.lanqiao.cn/problem.page?gpid=T4

#include <iostream>
using namespace std;

int main()
{
    int Fib_Front = 1, Fib_Rear = 1, Number, Answer;
    cin >> Number;
    for(int i = 3; i <= Number; i+=2)
    {
        Fib_Front = ((Fib_Front + Fib_Rear) > 10007)? (Fib_Front +Fib_Rear) % 10007 : (Fib_Front + Fib_Rear);
        Fib_Rear = ((Fib_Front + Fib_Rear) > 10007)? (Fib_Front +Fib_Rear) % 10007 : (Fib_Front + Fib_Rear);
    }
    Answer = (Number % 2 != 0)? Fib_Front:Fib_Rear;
    cout << Answer << endl;
    return 0;
}
#include <iostream>
using namespace std;
long long Arr[1000000];

void Fibonacci()
{
    Arr[0] = 0;
    Arr[1] = Arr[2] = 1;
    for(int i = 3; i < 1000000; i++)
    {
        Arr[i] = (Arr[i - 1] + Arr[i - 2])%10007;
    }
}
int main()
{
    int Number;
    Fibonacci();
    cin >> Number;
    cout << Arr[Number] << endl;
    return 0;
}

 

入门训练 Fibonacci数列

标签:ron   +=   using   names   ++   void   sin   span   !=   

原文:https://www.