Pagini recente » Cod sursa (job #2497484) | Profil linda | Cod sursa (job #1699693) | Cod sursa (job #576508) | Cod sursa (job #6232)
Cod sursa(job #6232)
#include<fstream.h>
#define input "fact.in"
#define output "fact.out"
int check(int p,int h,int gr)
{
if((p+gr)%h==0)
return 1;
while(h!=1)
{
if((p)%h==0)
return 1;
gr--;
h--;
h=h/5;
}
return 0;
}
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(check(p,(h*5)+1,gr))
fout<<"-1";
else
{
while(h!=1)
{
x-=(x/h);
h--;
h=h/5;
}
fout<<x*5;
}
}
else
if(p==0)
fout<<"1";
fout<<"\n";
return 0;
}