Cod sursa(job #1801381)

Utilizator RazvanGutaGuta Razvan Alexandru RazvanGuta Data 8 noiembrie 2016 22:44:28
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include<fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long p,st,dr,mij,ok;
int nrzero (int x)
{
    int i=5,t=0,k=0;
    while(i<=x)
    {
        k=k+x/i;
        i*=5;
    }
    return k;
}
int main ()
{
    f>>p;
    if(p==0)
    {
        g<<1;
        return 0;
    }
    ok=0;
    st=1;
    dr=5*p;
    while(st<=dr)
    {
        mij=st+(dr-st)/2;
        if(nrzero(mij)==p)
           ok=1;

        if(nrzero(mij)>=p)
        dr=mij-1;
        else
        st=mij+1;
    }
    if(ok==1)
        g<<st;
    else
        g<<-1;
}