Cod sursa(job #6336)
Utilizator | Data | 18 ianuarie 2007 22:31:00 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.61 kb |
#include<fstream.h>
#define input "fact.in"
#define output "fact.out"
int check(int x,int p)
{
long z,ok;
z=5;
ok=0;
while(z<=x)
{
ok+=x/z;
z=z*5;
}
if(p==ok)
return 1;
else
return 0;
}
int main()
{
long long h,x,p,y,i;
int gr;
ifstream fin(input);
ofstream fout(output);
fin>>p;
x=p;
h=1;
gr=1;
if(x>=1)
{
while(h*5+1<x)
{
h=(h*5)+1;
gr++;
}
while(h!=1)
{
x-=(x/h);
h--;
h=h/5;
}
x=x*5;
if(check(x,p))
fout<<x;
else
fout<<"-1";
}
else
if(p==0)
fout<<"1";
fout<<"\n";
return 0;
}