【蓝桥】入门训练 Fibonacci数列
程序员文章站
2022-06-12 12:42:10
...
#include< iostream >
using namespace std;
int main()
{
long F[1000001]={0};
F[0] = 0;
F[1] = F[2] =1;
F[3] = F[2]+F[1];
long n;
cin>>n;
if(n<1 || n>1000000)
cout<<"n was not in scope!"<<endl;
else if(n == 1 || n == 2)
cout<<F[1]<<endl;
else if(n==3)
cout<<F[3]<<endl;
else{
long i;
for(i=4;i<=n;i++){
F[i] = (F[i-1]+F[i-2])%10007;
}
cout<<F[--i]<<endl;
}
return 0;
}