Cod sursa(job #3221674)
Utilizator | Munteanu Mihnea Gabriel InformaticianInDevenire1 | Data | 7 aprilie 2024 19:54:53 |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.62 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
int nrfactori5(int p) {
int pow5 = 5,nr5 = 0;
while (pow5<=p) {
nr5 += p/pow5;
pow5 *= 5;
}
return nr5;
}
int main()
{
int p;
fin >> p;
if (p==0){
fout << 1;
}else{
int L = 1,R = 999999999,M;
while (L<=R){
M = (L+R)/2;
if (nrfactori5(M)<p){
L = M+1;
}else{
R = M-1;
}
}
if (nrfactori5(L)==p) fout << L;
else fout << -1;
}
return 0;
}