Pagini recente » Cod sursa (job #3256547) | Cod sursa (job #404617) | Cod sursa (job #2926839) | Rating Tiberiu Niculae (bestman4111) | Cod sursa (job #786638)
Cod sursa(job #786638)
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
long long int n, st, dr, p, c, nrz;
long long int numarzerouri(int x)
{
int i=0;
while(x)
{
x/=5;
i+=x;
}
return i;
}
int main()
{
fin>>p;
if(p==0) fout<<1;
else
{
st=0;
dr=1000000000;
n=1;
if(p>0){
while(n){ c=(st+dr)/2;
nrz=numarzerouri(c);
if(nrz==p&&st==dr) {n=st;break;}
if(dr<st) {n=-1;break;}
if(p>nrz) st=c+1;
else dr=c-1;
}
}
if(st==dr) fout<<n;
}
}