Cod sursa(job #545765)

Utilizator lazarliviaLazar Livia lazarlivia Data 3 martie 2011 21:30:46
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include<iostream.h>
#include<fstream.h> 
int catezerouri(int n)
 {
	 int k=0,x;
	if(n<=4) return 0;
	int i=1;
	while(i<=n) 
	{	x=i;
		while(x%5==0)
	{
		k++;
		x=x/5;
	}
		i++;
	}
return k;
 }

int main()
{
	int p,x;
	bool gasit=false;
	ifstream f("fact.in");
	ofstream g("fact.out");
	
	f>>p;
	if(p==0) g<<1;
	else
	{
	int mij,st=0, dr=1000000;
	while(1)
	{
		mij=(st+dr)/2;
		if(catezerouri(mij)==p) {g<<mij; gasit=true;break;}
		else
			if(catezerouri(mij)<p) st=mij+1;
		else dr=mij-1;
	}
	/*for(x=1;x<=1000000;x++)
	{
		if(catezerouri(x)==p){ g<<x; gasit=true;break;}
	}
		*/
	if(!gasit) g<<-1;
	}
return 0;	
}