Cod sursa(job #1225351)

Utilizator ovidiuz98Zamfir Ovidiu ovidiuz98 Data 2 septembrie 2014 14:13:13
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>

using namespace std;

ifstream f("fact.in");
ofstream g("fact.out");
long p;
int nrzero(long x)
{
    long nr5=5,nr=0;
    while(nr5<=x)
    {
        nr+=x/nr5;
        nr5*=5;
    }
    return nr;
}
int cautbin(long st,long dr)
{long x;
    if(st==dr)
    {if(nrzero(st)==p) {return st;}}
    else{
    int m=(st+dr)>>1;
    if(nrzero(m)>=p)
        {x=cautbin(st,m);}
    else
        {x=cautbin(m+1,dr);}
    return x;}
}
int main()
{
    f>>p;f.close();
    if(p==0) {g<<1;return 0;}
    long nr=cautbin(p,5*p);
    if(!nr) g<<-1;
    else g<<nr;
    g.close();
    return 0;
}