Pagini recente » Cod sursa (job #452688) | Cod sursa (job #1786372) | Cod sursa (job #1352177) | Cod sursa (job #1407146) | Cod sursa (job #1251963)
#include<cstdio>
using namespace std;
int pow5(int n)
{
int s=0;
long long p=5;
while(p<=n)
{
s=s+n/p;
p=p*5;
}
return s;
}
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
int p,st=1,dr=1000000000,med,last=-1,s;
scanf("%d",&p);
///search
while(st<dr){
med=(st+dr)/2;
s=pow5(med);
if (s>p){
dr=med-1;
}
if (s<p){
st=med+1;
}
if (s==p){
last=med;
dr=med-1;
}
}
if (pow5(st)==p){
last=st;
}
printf("%d\n",last);
return 0;
}