Cod sursa(job #2357587)
Utilizator | Data | 27 februarie 2019 16:11:21 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.83 kb |
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long n,i,j,st,dr,m;
int gasit;
int nr_zero(long long x)
{
int nr=0;
while (x)
{
nr+=x/5;
x=x/5;
}
return nr;
}
int main()
{
f>>n;
if (n==0)
g<<1;
else
{
st=1;
dr=999999999;
gasit=0;
while (st<=dr && gasit==0)
{
m=(st+dr)/2;
if (nr_zero(m)<n)
st=m+1;
else
if (nr_zero(m)>n)
dr=m-1;
else
gasit=1;
}
if (gasit==1)
{
while (nr_zero(m)==n)
m--;
g<<m+1;
}
else
g<<-1;
}
return 0;
}