Cod sursa(job #174888)
Utilizator | Data | 9 aprilie 2008 12:33:48 | |
---|---|---|---|
Problema | Factorial | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.4 kb |
#include<fstream.h>
#include<iostream.h>
int main(void)
{
fstream f,g;
long int x=1,p,temp=0,i;
f.open("fact.in",ios::in);
f>>p;
f.close();
while(x<p)
x=x*5+1;
x=(x-1)/5;
g.open("fact.out",ios::out);
if(p==0)
g<<1;
else
{
if(p%x==5)
g<<-1;
else
{
for(i=6;i<=x;i=i*5+1)
temp=temp+p/i;
g<<(p-temp)*5;
}
}
return 0;
}