题解 | #统计每个月兔子的总数#
统计每个月兔子的总数
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; }