Cod sursa(job #2364385)
| Utilizator | Data | 4 martie 2019 02:17:30 | |
|---|---|---|---|
| Problema | Factorial | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.71 kb |
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long p,st=1,dr=LONG_LONG_MAX,mid,howmany,retine;
long long zero(long long x)
{
int many=0;
while (x>0)
{
many+=x/5;
x/=5;
}
return many;
}
int main()
{
f>>p;
if (!p)
g<<"1";
else
{
while (st<=dr)
{
mid=(st+dr)/2;
howmany=zero(mid);
if (howmany==p)
{
retine=mid;
dr=mid-1;
}
else if (howmany<p)
st=mid+1;
else
dr=mid-1;
}
g<<(retine>0?retine:-1);
}
}
