Cod sursa(job #3193659)
Utilizator | Cosac Robert-Mihai RobertC2008123 | Data | 15 ianuarie 2024 11:51:34 |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.79 kb |
#include <fstream>
#include <climits>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int main ()
{
long long p;
bool ok=0;
f >> p;
if (p==0) g << 1;
else {
long long st=1, dr=INT_MAX, retine=0;
while (st<=dr)
{
int mij=st+(dr-st)/2;
int nr5=5;
int s=0;
while (nr5<=mij)
{
s+=mij/nr5;
nr5*=5;
}
if (s<=p)
{
if (s==p)
{
ok=1;
retine=mij;
st=mij+1;
break;
}
retine=mij;
st=mij+1;
}
else dr=mij-1;
}
if (ok) g << retine-retine%5;
else g << -1;
}
}