Mai intai trebuie sa te autentifici.
Cod sursa(job #801930)
Utilizator | Data | 25 octombrie 2012 14:33:03 | |
---|---|---|---|
Problema | Factorial | Scor | 85 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.5 kb |
#include<stdio.h>
int n,min,max,p,last,x;
int ok(int x)
{
int i=1,l=1,s=0;
while(l<x)
{
l*=5;
s+=x/l;
i++;
}
if(s>=p)
{
return 1;
}
return 0;
}
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
max=p*5;
min=1;
while(min<=max)
{
x=(min+max)/2;
if(ok(x))
{
last=x;
max=x-1;
}
else
{
min=x+1;
}
}
if(last!=0)
{
printf("%d",last);
}
else
{
printf("-1");
}
return 0;
}