Cod sursa(job #562819)

Utilizator andreipasalauPasalau Andrei andreipasalau Data 23 martie 2011 22:29:05
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include<iostream.h>
#include<fstream.h>
#include<math.h>
ifstream f("fact.in");
ofstream g("fact.out");
main()
{
	
	int i,p,n,k=1;
	f>>p;
	if(p<0) g<<"-1";
	else if(p==0) g<<"1";
	else if(p==1)g<<"5";
	else
	{
		 int m;
		 m=p;
		 int ok=1;
	    for(i=1;i<=pow(5,m);i++)
		{
			if(p==0) {g<<i-1;break;ok=0;}
			if(i%5==0){p--;
			int x;
			x=pow(5,k);
			if(i%x==0)p-=k;
			if(i/5==pow(5,k))k++;
			
		}
		
	 }if(ok) g<<"-1";	
	}
	
}