Pagini recente » Cod sursa (job #667154) | Cod sursa (job #1944567)
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p;
int check(int val){
int f=5,s=0;
int x=val;
while(x/f){
s+=x/f;
f*=5;
}
return f;
}
int caut(){
int l=1,r=500000000,sol=-1,mid;
while(l<=r){
mid=(l+r)/2;
int a=check(mid);
if(a>p){
r=mid-1;
}else if(a<p){
l=mid+1;
}else{
return mid;
}
}
return sol;
}
int main()
{
fin>>p;
if(p==0)
fout<<1;
else{
int a=caut();
if(a){
fout<<a-a%5;
}else{
fout<<-1;
}
}
return 0;
}