Cod sursa(job #1722311)

Utilizator antracodRadu Teodor antracod Data 27 iunie 2016 20:34:37
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream in('fact.in');
ofstream out('fact.out');

long int low=1,mid,high=500000000,answer;
long int x;

int nrzero(int n)
{
    long int five=5,result=0;
    while(n>=five)
    {
        result=result+n/five;
        five=five*5;
    }
        return result;
}

int BinarySearch(int p)
{
    answer=1;
    while(low<=high)
    {
        mid=low+(high-low)/2;
        x=nrzero(mid);
        if(x==p)
        {
            answer=mid;
            high=mid-1;
        }
        else if(x<p)
        {
            low=mid+1;
        }
        else
        {
            high=mid-1;
        }
    }
    return answer;
}

int main()
{
    long int p,x;
    in>>p;
    x=BinarySearch(p);
    out<<x;
}