Cod sursa(job #12950)
Utilizator | Data | 5 februarie 2007 12:42:15 | |
---|---|---|---|
Problema | Factorial | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.37 kb |
#include<fstream.h>
int main(){
ifstream in("fact.in");
ofstream out("fact.out");
long n,p,i,e=5,f=0,s=0,x=0,j=1;
in>>p;
i=1;
if(p==0)
out<<1<<"\n";
else
{while(s!=p)
{
i=1;
if(j%e==0){
f++;
i=i+f;
e=e*5;
}
s=s+i;
x++;
j++;
if(s>p)
out<<-1<<"\n";
}
out<<x*5<<"\n";}
in.close();
out.close();
return 0;
}