Cod sursa(job #3162380)
| Utilizator | Data | 29 octombrie 2023 07:27:21 | |
|---|---|---|---|
| Problema | Factorial | Scor | 90 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.74 kb |
#include <fstream>
#include<cmath>
using namespace std;
long long int factori_5(long long int x) {
int cnt = 0;
while (x > 0) {
if (x % 5 == 0) {
x /= 5;
cnt++;
}
if (x % 5 != 0)
break;
}
return cnt;
}
int main() {
ifstream cin("fact.in");
ofstream cout("fact.out");
int p;
cin >> p;
long long int r = 0;
long long i = 5;
if (p == 0)
cout << 1;
else {
while (1) {
p -= factori_5(i);
if (p == 0) {
cout << i;
break;
}
if (p < 0) {
cout << -1;
break;
}
i += 5;
}
}
return 0;
}
