Cod sursa(job #991559)

Utilizator Darius15Darius Pop Darius15 Data 30 august 2013 19:31:40
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <fstream>

using namespace std;
int p,st,dr,fact5,k,mij;
ifstream f("fact.in");
ofstream g("fact.out");
int main()
{
    f>>p;
    st=1,dr=500000000;
    while(st<=dr)
    {
        fact5=5,k=0,mij=(st+dr)/2;
        while (fact5<=mij)
            k+=mij/fact5,fact5*=5;
            if (k==p) break;
            else if (k>p) dr=mij-1;
                 else st=mij+1;
    }
    mij=mij-mij%5;
    if (p==0) g<<1;
    else if (st<=dr) g<<mij;
         else g<<-1;
    return 0;
}