Cod sursa(job #1004535)

Utilizator lucky1992Ion Ion lucky1992 Data 2 octombrie 2013 22:30:54
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>

using namespace std;

ifstream in("fact.in");
ofstream out("fact.out");
//int NMAX = 1000000000;

int f( int x ){

	int rez = 0;
	int a = 5;
	while(1){
		rez += x/a;
		if( x/a == 0 )
			break;
		a *= 5;
	}
	
	return rez;

}



int main(){

	int p;
	in >> p;
	
	int left = 1, right = 1000000000, mid, temp, rez = -1;
	
	
	cout<< f(1000) <<endl;
	while( left <= right ){
	
		mid = left + (right-left)/2;
		temp = f(mid);
		
		if( temp == p ){
			rez = mid;
			break;
		}
		else if( temp < p )
			left = mid + 1;
		else
			right = mid - 1;
	
	}
	if(rez != -1)
		while( rez%5 != 0 ) rez--;
	if(p==0)
		rez = 1;
		
	out<<rez<<endl;
	
	return 0;
	
}