Cod sursa(job #2291705)
| Utilizator | Data | 28 noiembrie 2018 15:26:47 | |
|---|---|---|---|
| Problema | Factorial | Scor | 90 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.65 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
bool number_of_zeros(int nr, int n){
int rez = 0;
for(int i = 5; i <= nr ; i *= 5){
rez += nr / i;
}
return (rez >= n);
}
int main(){
int n, fact;
in >> n;
if (n == 0){
out << 1 << "\n";
return 0;
}
if (n == 1){
out << "5\n";
return 0;
}
int low = 0;
int high = 5 * n;
while (low < high){
int mid = (low + high) / 2;
if (number_of_zeros(mid, n))
high = mid;
else
low = mid + 1;
}
out << low << endl;
}