Cod sursa(job #1981108)

Utilizator xtreme77Patrick Sava xtreme77 Data 14 mai 2017 19:59:10
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>
#include <cmath>

using namespace std ;

ifstream cin ("fact.in") ;
ofstream cout ("fact.out") ;

long long zeros (int n) 
{
	long long S = 0 ;
	while (n / 5) {
		S = S + n / 5 ; 
		n /= 5 ;
	}
	return S ;
}

int main(int argc, char const *argv[])
{
	int p ; 
	cin >> p ;
	int valmax = (p + 1) * 5 ;
	int bucket = (int)sqrt((double)valmax) ;
	for (int i = 1 ; i <= valmax ; i += bucket) {
		if (zeros (i) >= p) {
			// cout << "pentru " << i << " " << zeros (i) << '\n' ;
			for (int j = max (i - bucket, 1) ; j <= i ; ++ j) {
				if (zeros (j) == p) {
					cout << j ;
					return 0 ; 
				}
			}
			break ;
		}
	}
	cout << -1 ;
	return 0;
}