当前位置: 代码迷 >> 综合 >> HDU 1568 Fibonacci 公式 *
  详细解决方案

HDU 1568 Fibonacci 公式 *

热度:76   发布时间:2023-09-23 03:49:56.0

题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2&sectionid=2&problemid=1

试了用JAVA WR

思路来自:http://blog.csdn.net/niushuai666/article/details/7013352

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cmath>
#include <sstream>
#include <vector>
using namespace std;
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define REPD(i,a,b) for(int i=a;i>=(int)b;i--)int f[21];
int main()
{f[0]=0; f[1]=1; REP(i,2,20+1) f[i]=f[i-1]+f[i-2];int n;while(scanf("%d",&n)==1){if(n<=20) {printf("%d\n", f[n]);continue;}double t=-0.5*log(5.0)/log(10.0) + (double(n)*log((sqrt(5.0)+1.0)/2.0)/log(10.0));t-=floor(t);   //取小数t=pow(10,t);while(t<1000) t*=10;printf("%d\n", int(t));}return 0;
}