Cod sursa(job #545825)

Utilizator lazarliviaLazar Livia lazarlivia Data 3 martie 2011 22:46:59
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include<iostream.h>
#include<fstream.h> 
int catezerouri(long long 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()
{
long long p;
int x;
	bool gasit=false;
	ifstream f("fact.in");
	ofstream g("fact.out");
	
	f>>p;
	if(p==0) g<<1;
	else
	{
	long long mij,st=1, dr=5*p;
	while(st<dr)
	{
		mij=(st+dr)/2;
		x=catezerouri(mij);
		if(x==p) {
			
			while(catezerouri(mij)==p) mij--;
			g<<mij+1; gasit=true;break;}
		else
			if(x<p) st=mij+1;
		else dr=mij-1;
	}

	if(!gasit) g<<-1;
	}
return 0;	
}