警世钟
查看原帖
警世钟
777400
_Coqwq_楼主2024/10/24 19:11

如果你懒得打斐波那契数列,像我一样直接套了公式

#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分

而如果你把floatfloat 改成 doubledouble

#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;
}

就对了

2024/10/24 19:11
加载中...