Pagini recente » Cod sursa (job #672462) | Cod sursa (job #561970) | Cod sursa (job #2864485) | Cod sursa (job #1400000) | Cod sursa (job #6224)
Cod sursa(job #6224)
#include<fstream.h>
#define input "fact.in"
#define output "fact.out"
int main()
{
long long h,x,p;
int gr;
ifstream fin(input);
ofstream fout(output);
fin>>p;
x=p;
h=1;
gr=0;
if(p>=1)
{
while(h*5+1<=p)
{
h=(h*5)+1;
gr++;
}
if(((p+gr)%(h*5+1))<gr)
fout<<"-1"<<"\n";
else
{
while(h!=1)
{
x-=(x/h);
h--;
h=h/5;
}
fout<<x*5;
}
}
else
if(p==0)
fout<<"1";
fout<<"\n";
return 0;
}