Cod sursa(job #923814)

Utilizator SagunistuStrimbu Alexandru Sagunistu Data 23 martie 2013 21:08:57
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <iostream>
#include <fstream>
#include <limits.h>

using namespace std;
int p,st,dr,med,s,m,x,r;
int factzero(int m)
{int n,s;
 n=5;
 s=0;
 while(m>=n)
    {s+=m/n;
     n=n*5;
    }
 return s;
}
int main()
{ifstream fin("fact.in");
ofstream fout("fact.out");
fin>>p;
if(p==0)
    fout<<"1";
else
{
st=1;
dr=1000000000;
while(st<=dr)
    {med=(st+dr)/2;
     x=factzero(med);
     if(x==p)
        break;
     else
     if(x<=p)
        st=med+1;
     else
        dr=med-1;
    }
if(st>dr)
    fout<<"-1";
else
    {r=med%5;
     fout<<med-r;
    }
}
    return 0;
}