如果你懒得打斐波那契数列,像我一样直接套了公式
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
float t1 = 1 + sqrt(5);
float t2 = 1 - sqrt(5);
float ans = ( pow( t1 / 2 , n) - pow ( t2 / 2 , n ) ) / sqrt (5);
printf ("%.2lf",ans);
return 0;
}
这样只会得20分
而如果你把float 改成 double
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
double t1 = 1 + sqrt(5);
double t2 = 1 - sqrt(5);
double ans = ( pow( t1 / 2 , n) - pow ( t2 / 2 , n ) ) / sqrt (5);
printf ("%.2lf",ans);
return 0;
}
就对了