20241015每日一题洛谷P1720

从0.5开始的C语言学习 / 2024-10-19 / 原文

入门 洛谷 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公式,简单代入即可