Cod sursa(job #1925258)
| Utilizator | Data | 12 martie 2017 19:10:03 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <bits/stdc++.h>
using namespace std;
long long n, p = 1, S, mij;
int zero(int x){
int y = 5, nr = 0;
while (y <= x){
nr += x / y;
y *= 5;
}
return nr;
}
int main(){
ifstream cin("fact.in");
ofstream cout("fact.out");
cin >> n;
S = n * 5;
while (p <= S){
mij = (S + p) / 2;
if (zero( mij ) >= n)
S = mij - 1;
else
p = mij + 1;
}
if (n == 0)
cout << '1';
else if (zero( p ) == n)
cout << p;
else
cout << "-1";
return 0;
}
