Pagini recente » Cod sursa (job #2786834) | Cod sursa (job #793317) | Cod sursa (job #2943093) | Cod sursa (job #1896762) | Cod sursa (job #2291717)
#include <bits/stdc++.h>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
bool number_of_zeros(int nr, int n, int option){
int rez = 0;
for(int i = 5; i <= nr ; i *= 5){
rez += nr / i;
}
switch (option){
case 1:
return (rez >= n);
break;
case 0:
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, 1))
high = mid;
else
low = mid + 1;
}
if (number_of_zeros(low, n, 0))
out << low << endl;
else
out << "-1\n";
return 0;
}