Pagini recente » Cod sursa (job #1819063) | Cod sursa (job #3351229) | Cod sursa (job #2831052) | Cod sursa (job #948241) | Cod sursa (job #2398006)
#include <fstream>
//#define f cin
//#define g cout
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
typedef unsigned long long ull;
ull n,nr,tot,i,k;
ull dv5(ull n)
{
ull k=0;
while(n%5==0)
{
n/=5;
++k;
}
return k;
}
int main()
{
f>>n;
if(n==0)
{
g<<0;
return 0;
}
nr=n*5;
tot=n;
i=25;
k=1;
while(i<nr)
{
tot+=nr/i*k;
++k;
i*=5;
}
while(tot>n)
{
tot-=dv5(nr);
nr-=5;
}
if(tot!=n)
g<<-1;
else
g<<nr;
}