20241015每日一题洛谷P1720

入门 洛谷 P1720 月落乌啼算钱(斐波那契数列)

#include<iostream>
#include<cstdio>
#include <cmath>

int main()
{
	int n;
	scanf("%d", &n);
	double ans = 0;
	ans = (pow(((1 + sqrt(5)) / 2), n) - pow(((1 - sqrt(5)) / 2), n)) / sqrt(5);
	printf("%.2lf", ans);
	return 0;
}

题目已给出算ans公式,简单代入即可

posted @ 2024-10-15 15:43  才瓯  阅读(14)  评论(0)    收藏  举报