Pagini recente » Cod sursa (job #1001240) | Cod sursa (job #2499085) | Cod sursa (job #2783653) | Cod sursa (job #800921) | Cod sursa (job #562232)
Cod sursa(job #562232)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int NrZero(int x){
int z=0;
for (long long i=5; i<=x; i*=5)
z+=x/i;
return z;
}
int BS(int p){
int l=0, r=p*10, m,z;
if (p==0)
return 1;
while (l<=r){
m=(l+r)/2;
z=NrZero(m);
if (z==p){
while (m%5 != 0)
m--;
return m;
}
else
if (z>p)
r=m-1;
else
l=m+1;
}
return -1;
}
int main(){
int p;
fin>>p;
fout<<BS(p);
fin.close();
fout.close();
return 0;
}