Pagini recente » Cod sursa (job #1397688) | Cod sursa (job #1194993) | Cod sursa (job #1212189) | Cod sursa (job #2583703) | Cod sursa (job #2445171)
#include <bits/stdc++.h>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
long long p;
int countingFive(int n){
int s=0,five=5;
while(n>=five){
s+=n/five;
five*=5;
}
return s;
}
int BS (int st, int dr, int p){
int mij, poz=-1;
while (st<=dr){
mij = st + (dr-st) / 2;
int Five=countingFive(mij);
if (Five==p){
poz=mij;
dr=mij-1;
}
else
if(Five>p)
dr=mij-1;
else
st=mij+1;
}
return poz;
}
int main(){
in>>p;
out << BS(1,500000000,p);
return 0;
}