Cod sursa(job #562125)

Utilizator SkillZoneOvy The Best SkillZone Data 22 martie 2011 13:03:05
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include<fstream>
using namespace std;
long fact(int m){
	long nr=0;
	while(m/5){
			m/=5;
			nr+=m;
			}
	return nr;
	}

int main(){
	long long p,i,m,j=900000030;
	ifstream in;
	in.open("fact.in");
	in>>p;
	in.close();
	ofstream out("fact.out");
	if(p==0){
		out<<1;
		return 0;
	}
	for(i=1;i<=j;){
		m=(i+j)/2;
		if(fact(m)==p){
			while(m%10!=5&&m%10!=0)
				m--;
			out<<m;
			break;
			}
		else if(fact(m)<p)
			i=m+1;
		else
			j=m-1;
		if(i==j)
			out<<-1;
		}
	return 0;
	}