Cod sursa(job #1722314)

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

using namespace std;

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

long long int low=1,mid,high=1000000000,answer;
long 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 long int p,x;
    cin>>p;
    x=BinarySearch(p);
    cout<<x;
}