斐波那契数列对10007取余数
作者:互联网
Mn = ( Mn-1 + Mn-2 ) % 10007
因为
*F(n) = X1 * 10007 + Mn
F(n+1) = X2 * 10007 +Mn+1
F(n+2) = F(n) + F(n+1)
=(X1 + X2)+100007 + Mn + Mn+1
Mn+2 = F(n+2) / 10007 = Mn + Mn+1
所以 Mn = ( Mn-1 + Mn-2 ) % 10007
#include <iostream>
int main()
{
int a = 1,b = 0, sum = 0,t = 0, n;
std::cin >> n;
while ( ++t <= n )
{
sum = ( a + b ) % 10007;
a = b;
b = sum;
}
std::cout << sum;
return 0;
}
Yicay
发布了1 篇原创文章 · 获赞 0 · 访问量 12
私信
关注
标签:10007,int,Mn,斐波,文章,X2,那契,X1 来源: https://blog.csdn.net/qq_15757015/article/details/104089657