Cod sursa(job #2410428)
| Utilizator | Data | 20 aprilie 2019 02:30:13 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.69 kb |
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long p,WK;
int nr0(long long n)
{
long long k=5,s=0;
while (n/k)
{
s+=n/k;
k*=5;
}
return s;
}
int rez(long long a)
{
for (long long i=a-sqrt(WK); i<=a; i++)
if (nr0(i)==p)
return i;
return -1;
}
int main()
{
f>>p;
if (p==0)
{
g<<1;
return 0;
}
WK=p*5;
long long a=1;
while (a<=WK)
{
if (nr0(a)>=p)
{
g<< rez(a);
return 0;
}
else a+=sqrt(WK);
}
}
