Mai intai trebuie sa te autentifici.
Cod sursa(job #2788803)
Utilizator | Data | 26 octombrie 2021 14:46:27 | |
---|---|---|---|
Problema | Factorial | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.86 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int nz(int n)
{
long long c=5,S=0;
while(c<=n)
{
S=S+n/c;
c=c*5;
}
return S;
}
int p,n;
int main()
{
fin>>p;
if(p==0)
{
fout<<1;
}
else
{
int st=1;
int dr=100000000;
int ok=0,poz=-1;
while(st<=dr)
{
int mij=(st+dr)/2;
if(nz(mij)==p)
{
ok=1;
poz=mij;
st=dr+1;
}
else
{
if(nz(mij)<p)
{
st=mij+1;
}
else
{
dr=mij-1;
}
}
}
if(ok==0)
{
fout<<-1;
}
else
{
fout<<poz-poz%5;
}
}
return 0;
}