Pagini recente » Cod sursa (job #3127245) | Cod sursa (job #2872121) | Cod sursa (job #2961686) | Cod sursa (job #1631115) | Cod sursa (job #916216)
Cod sursa(job #916216)
#include <iostream>
#include <fstream>
using namespace std;
long p,k,nr,h,i,hh,OK;
int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
fin>>p;
k=0;
nr=0;
h=0;
i=156;
if(p==0)fout<<"1";
else
{
while(nr+i<=p)
{
nr+=i;
h+=625;
k++;
hh=h;
while(hh%5==0)
{
nr++;
hh/=5;
}
nr-=4;
}
if(nr==p)fout<<h;
else
{
while(nr<p)
{
h+=5;
hh=h;
while(hh%5==0)
{
nr++;
hh/=5;
}
}
if(p==nr) fout<<h;
else fout<<"-1";
}
}
fin.close();
fout.close();
}