Cod sursa(job #793278)

Utilizator mihaitsMihai Zavoian mihaits Data 2 octombrie 2012 14:04:42
Problema Factorial Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <fstream>
#include <iostream>
using namespace std;

int s = 1, d = 100000000, m, p, k, j;

int functie ( int x )
{
	k =0;
	j = 5;
	while ( j < x )
	{
		k += x/j;
		j *= 5;
	}
	return k;
}

int main ( void )
{
	ifstream fin ( "fact.in" );
	ofstream fout ( "fact.out" );
	
	fin >> p;
	
	while ( s < d )
	{
		int x = functie ( ( s + d ) / 2 );
		if ( x >= p )
			d = ( s + d ) / 2;
		if ( x < p )
			s = ( s + d ) / 2 + 1;
		
	}
	fout << s;
	
	fin.close();
	fout.close();
}