Cod sursa(job #705809)

Utilizator vladhVlad Harbuz vladh Data 4 martie 2012 23:11:25
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include<fstream>
#include<math.h>
using namespace std;
unsigned g_p;
ifstream in("fact.in");
ofstream out("fact.out");
unsigned nr_zero_fact(unsigned n){
	unsigned q=1,c=1,s=0;
	while(q!=0){
		q=(unsigned)floor((double)n/pow((double)5,(double)c));
		s+=q;
		c++;
	}
	return s;
}
unsigned cautare(unsigned i, unsigned j){
	unsigned x=(i+j)/2;
	if(nr_zero_fact(x)==g_p){
		while(nr_zero_fact(x-1) == nr_zero_fact(x)){
			x--;
		}
		return x;
	}else if(nr_zero_fact(x)>g_p){
		return cautare(i,x);
	}else if(nr_zero_fact(x)<g_p){
		return cautare(x,j);
	}else{
		out<<"ERROR: out of range";
		exit(0);
	}
}
int main(){
	in>>g_p;
	out<<cautare(1,INT_MAX);
	return 0;
}