Cod sursa(job #822142)

Utilizator stirbucatalinstirbu catalin stirbucatalin Data 22 noiembrie 2012 22:24:08
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <stdio>
 
using namespace std;

int zero(int x)
{
int z=0;
while(x>=1)
{
x/=5;
z+=x;
}
 
return z;
}
 
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
 
int p;
int mid;
int st,dr;
st=0;
dr=(1<<31)-1;
 
scanf("%d",&p);
 
if(p==0)
{
printf("1");
return 0;
}
 
bool ok=true;
 
while(st<=dr && ok)
{
mid=(st+dr)/2;
if(zero(mid) == p)
ok=false;
else
if(zero(mid)<p)
st=mid+1;
else
dr=mid-1;
}

if(ok)
printf("-1");
else
{
while(mid%5)
--mid;
printf("%d",mid);
}
 
return 0;
}