斐波那契(通项公式)

通项公式:

 1 #include<iostream>
 2 #include<cmath>
 3 using namespace std;
 4 int main()
 5 {
 6     double a,n,ans;
 7     cin>>n;
 8     //n--;  //(第一项是0时)
 9     a=sqrt(5);
10     ans =(a/5) * (pow( (1+a)/2 ,n) - pow((1-a)/2 ,n));
11     cout<<ans; 
12     return 0; 
13 }

 

posted @ 2017-04-20 20:21  MJT12044  阅读(376)  评论(0编辑  收藏  举报