7_7_2013 E.Function

Problem E: Function

Time Limit: 1 Sec   Memory Limit: 32 MB
Submit: 52   Solved: 26
[ 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

1 1 3

Sample Output

2.0000

#include <iostream>
#include <stdio.h>
using namespace std;
int
main()
{
    //freopen("fun.in", "r", stdin);
    //freopen("fun.out", "w", stdout);
    int m;
    double a[100];
    while(~scanf("%lf %lf %d", &a[0], &a[1], &m)){
        for (int i=2; i<10; i++){
            a[i]=(a[i-1]+1.0)/a[i-2];
        }

        //for(int i=0; i<10; i++)
            //printf("%.6lf", a[i]);
        printf("%.6lf\n", a[(m-1)%5]);

        //printf("%.6lf\n", a[m]);
    }
    return 0;
}



你可能感兴趣的:(7_7_2013 E.Function)