Pagini recente » Cod sursa (job #2401647) | Cod sursa (job #2519397) | Cod sursa (job #2439186) | Cod sursa (job #2866201) | Cod sursa (job #6220)
Cod sursa(job #6220)
#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==0)
fout<<"0";
else
{
while(h*5+1<=p)
{
h=(h*5)+1;
gr++;
}
if(p+gr>=(h*5)+1)
fout<<"-1"<<"\n";
else
{
while(h!=1)
{
x-=(x/h);
h--;
h=h/5;
}
fout<<x*5<<"\n";
}
}
return 0;
}