Pagini recente » Cod sursa (job #2904180) | Cod sursa (job #2190153) | Cod sursa (job #1417851) | Cod sursa (job #1309567) | Cod sursa (job #1694274)
#include <fstream>
using namespace std;
int trailingZeros(int n){
int cnt = 0;
while(n!=0){
n = n/5;
cnt += n;
}
return cnt;
}
int main(){
int p;
ifstream fin("fact.in");
fin>>p;
fin.close();
ofstream fout("fact.out");
int a = 0; int b = 5*p;
int mid;
int midZeros;
if(p==0){
fout<<1;
goto exit;
}
while(a!=b){
mid = (a+b)/2;
midZeros = trailingZeros(mid);
if(midZeros>p){
b=mid;
continue;
}
if(midZeros<p){
a=mid;
continue;
}
goto found;
}
fout<<-1;
goto exit;
found:
fout<<mid-mid%5;
exit:
fout.close();
return 0;
}