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