Cod sursa(job #1694248)
| Utilizator | Data | 24 aprilie 2016 23:27:56 | |
|---|---|---|---|
| Problema | Factorial | Scor | 85 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.74 kb |
#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 mid;
int midZeros;
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;
}
