Cod sursa(job #1309748)

Utilizator andreix2cAndrei Cosmin andreix2c Data 5 ianuarie 2015 23:44:59
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <fstream>
#include <limits>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int p,st=1,dr=numeric_limits<int>::max(),mij,nr0;
int main()
{
    f>>p;
    while(st<=dr)
    {
        mij=(dr+st)/2;
        nr0=0;
        for(int i=5; i<=mij; i*=5)
            nr0+=mij/i;
        if(nr0<p)
            st=mij+1;
        else if(nr0>=p)
            dr=mij-1;
    }
    nr0=0;
    for(int i=5; i<=st; i*=5) nr0+=st/i;
    if(nr0==p)
        g<<st;
    else g<<"-1";
    f.close();
    g.close();
    return 0;
}