#include <iostream>
#include <fstream>

using namespace std;

int fibonacci (int term) // return the term in the fibonacci series
{
    if (term == 1) //the first term is 1
             return 1;

    if (term == 2) //the second term is 1
             return 1;
    
    return fibonacci(term-1) + fibonacci(term-2); //add up the previous term and the previous previous term to obtain the current term
    
}

int main ()
{
    ifstream infile ;
    ofstream outfile ;
    infile.open ("DATA2.txt", ios::in) ;
    int answer[5], input[5], a = 1;
    
    for(int i =0; i <= 4; i ++)
    {
            infile >> input[i];
    }
    
    infile.close();
    
    outfile.open("OUT2.txt", ios::out);
    
    for (int l = 0; l <= 5; l++)
    {
        if ((input[l] >= 350704366) && (input[l] < 567451585))
        {
           answer[l]=433494437; 
           break;
           }
       if (input[l] >= 56451585 && input[l] < 918155951)
       {
          answer[l]=701408733;
           break;
           }
       if (input[l] >= 918155951 )
       {
          answer[l]=1134903170;
           break;
           }
    do
    {
        a ++;
        answer[l] = fibonacci(a);
    }while (input[l] > fibonacci (a));
    
    if (input[l] - fibonacci(a-1) < fibonacci(a) - input[l])
       answer[l] = fibonacci(a-1);
    }
       
    for(int i=0; i<5; i++)
    {
        outfile << answer[i] << "\n";      
    }
    
    outfile.close();
      
    system("PAUSE");
    return 0;
}

