题解 | #统计每个月兔子的总数#
统计每个月兔子的总数
https://www.nowcoder.com/practice/1221ec77125d4370833fd3ad5ba72395
#include<iostream>
#include<cmath>
#include<algorithm>
#include <ostream>
using namespace std;
int main(){
int n;
long ans;
while(cin >> n){
double sqrt5 = sqrt(5);
double fibN = pow((1 + sqrt5) / 2, n) - pow((1 - sqrt5) / 2, n);
ans = round(fibN / sqrt5);
cout << ans << endl;
}
return 0;
}
查看15道真题和解析
SHEIN希音公司福利 350人发布