Pagini recente » Cod sursa (job #458781) | Cod sursa (job #1363475) | Cod sursa (job #1068022) | Cod sursa (job #1892716) | Cod sursa (job #1693888)
#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 = 400000016;
int m;
while(a!=b){
m = (a+b)/2;
if(trailingZeros(m)>p){
b=m;
}
else if(trailingZeros(m)<p){
a=m;
}
else {
goto found;
}
}
fout<<-1;
goto exit;
found:
while(trailingZeros(m)==p) m--;
fout<<m+1;
exit:
fout.close();
return 0;
}