Cod sursa(job #221271)

Utilizator cercelcercel maria luiza cercel Data 15 noiembrie 2008 13:52:48
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include<fstream.h>
fstream f,g;
long p,n,i,k;
long nrdiv5(long x);

int main(){
f.open("fact.in",ios::in);
f>>p;
f.close();
g.open("fact.out",ios::out);
if(p==0){
	n=1;
	g<<n;
	g.close();
	}
else{
	n=0;
	k=0;
	while(k<p){
		n=n+5;
		k=k+nrdiv5(n);
		}
	if(k==p)
		g<<n;
	else
		g<<-1;
	g.close();
	}
return 1;
}

long nrdiv5(long x){
long s=0;
while(x%5==0){
	s++;
	x=x/5;
	}
return s;
}