Cod sursa(job #1024075)

Utilizator leontinLeontin leontin Data 8 noiembrie 2013 10:16:06
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include<fstream>
using namespace std;

int p;


    ifstream f("fact.in");
    ofstream g("fact.out");
int fun(long long x)
{
    long long c=5,nr=0;
    while(x/c!=0)
    {
        nr=nr+x/c;
        c=c*5;
    }
    return nr;
}

int binary(long long st,long long dr)
{
    long long med,x;
    while(st<=dr)
    {
        med=(st+dr)/2;
        x=fun(med);
        if(p==x&&med%5==0)
        return med;
        else
        if(x<p)
        st=med+1;
        else
        dr=med-1;

    }
    return -1;
}

int main()
{


    long long n;
    f>>p;
    if(p==0)
        g<<1<<endl;
    else
    g<<binary(1,100000000)<<endl;
    return 0;
}