Fibonacci column deformation

Fibonacci column deformation title

The meaning of problems

Fibonacci generation rule f (n) = f (n -1) + f (n-2). Of Number of
input before the two Fibonacci numbers of Number of f1, f2, the output number range in the n-Fei the number of waves that deed.

input Output

A plurality of sets of test data, the test data of one line each, including three integers separated by spaces: f1, f2, n, where, \ (. 1 <= F1 <F2 = <= n-<10. 6 ^ \)
input to EOF End

Each set of test data output line, indicates that the number of conveyance with a Fibonacci number in the range of f1 ~ n (including n) is.

Problem-solving ideas

This topic is relatively simple and does not require the use of a matrix of what the power of fast, because the amount of data was \ (10 ^ 6 \) , simulation is also possible before.

#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
    int f1, f2, n;
    while(scanf("%d%d%d", &f1, &f2, &n)!=EOF) 
    {
        int ans=2, tmp=f1+f2;
        if(n==f2)
        {
            printf("2\n");
            continue;
        }
        while(tmp<=n)
        {
            ans++;
            f1=f2;
            f2=tmp;
            tmp+=f1;
        }
        printf("%d\n", ans);
    }
    return 0;
}

END

Guess you like

Origin www.cnblogs.com/alking1001/p/11230300.html