Function
Define a function f(n)=(f(n-1)+1)/f(n-2). You already got f(1) and f(2). Now, give you a number m, please find the value of f(m).
Input
There are several test cases. Each case contains three integers indicating f(1), f(2) and m ( 1 <= f(1), f(2), m <= 1000,000,000).
Output
For each case, please output the value of f(m), rounded to 6 decimal places.
Sample Input
1 1 3
Sample Output
2.000000
解题报告
此题仔细看来就是一个规律题目,这个数列,每隔五个循环一次,故只需要算出f[3]-f[7]即可,然后求f[m]=f[(m-1)%5],代码如下:
#include<stdio.h>
int main()
{
double f[7],a,b;
int m,i;
while(scanf("%lf%lf%d",&a,&b,&m)!=EOF)
{
f[0]=a;
f[1]=b;
for(i=2;i<7;i++)
f[i]=(f[i-1]+1.0)/f[i-2];
m=(m-1)%5;
printf("%lf\n",f[m]);
}
return 0;
}