Fibonacci數列求最高次項除以10007的餘數
但就求數列本身並不難,問題在於用最短的時間輪詢到當前最高次項
using System;
/*
Fibonacci數列的遞推公式爲:Fn = Fn-1+Fn-2,其中F1=F2=1。
當n比較大時,Fn也非常大,現在我們想知道,Fn除以10007的餘數是多少
*/
namespace demo
{
class Program
{
static void Main(string[] args)
{
int a = 0, b = 1, c = 1, F, n = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < n; i++)
{
c = a + b;
b = a;
a = c;
}
F = c % 10007;
Console.WriteLine(F);
}
}
}