题目来源:http://acm.nyist.net/JudgeOnline/problem.php?pid=461
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
//f(n)=n*log10((1+sqrt(5))/2)-log10(sqrt(5))
int main()
{
int arr[22];
arr[0] = 0, arr[1] = 1;
for(int i = 2; i <= 20; ++i)
arr[i] = arr[i-1] + arr[i-2];
int n, res, ans2;
double ans1, ans3;
while(~scanf("%d", &n))
{
if(n <= 20)
{
printf("%d\n", arr[n]);
continue ;
}
ans1 = n*log10(0.5+0.5*sqrt(5))-log10(sqrt(5));
ans2 = (int)ans1;
ans1 -= ans2;
ans3 = pow(10.0, ans1);
res = ans3*1000;
printf("%d\n", res);
}
return 0;
}