Pagini recente » Cod sursa (job #2889824) | Cod sursa (job #1977141) | Cod sursa (job #2351319) | Cod sursa (job #2389528) | Cod sursa (job #1183512)
#include <iostream>
using namespace std;
int fact(int n){
int x = 5,rez=0;
while(x <= n){
rez += n / x;
x *=5;
}
return rez;
}
int main()
{
ifstream f("fact.in");
ofstream g("fact.out");
int n,p;
f>>p;
int st = 1, dr = 100000000, ok = 0, m;
while(st < dr){
m = (st + dr) / 2;
if(p > fact(m)){
st = m + 1;
}
if(p < fact(m)){
dr = m - 1;
}
if(p == fact(m)){
ok = 1;
break;
}
}
while(fact(m) >= p){
if(fact(m) >= p)
--m;
}
if(ok)
g<<m+1;
else
g<<"-1";
return 0;
}