Problem E: Function
Time Limit: 1 Sec Memory Limit: 32 MBSubmit: 20 Solved: 16
[ Submit][ Status][ Web Board]
Description
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
Sample Output
#include<stdio.h>
double a,b;
long m;
double Re(int c)
{
if(c==1)
return a;
else if(c==2)
return b;
else if(c==0)
{
c=5;
return (double)(Re(c-1)+1)/Re(c-2);
}
else
return (double)(Re(c-1)+1)/Re(c-2);
}
int main(void)
{
while(scanf("%lf%lf%d",&a,&b,&m)==3)
{
double Result;
Result=Re(m%5);
printf("%.4lf\n",Result);
}
return 0;
}