Cod sursa(job #1604234)

Utilizator sandupetrascoPetrasco Sandu sandupetrasco Data 18 februarie 2016 08:25:39
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream>
#include <algorithm>

using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
int P; 
unsigned long long a,b,rs;
long long nrz( long long f ){
     int p = 0;
     while(f != 0)
     {
            p = p + f/5;
            f = f / 5;
     }
     return p;
}
int main(){
	cin >> P;
	a = 0; b = 1e10;
	while(a<=b){
	long long c = (a+b)/2;
	long long l = nrz(c);
	if(l < P) a = c+1;
	else if(l > P) b = c-1;
	else if(l == P){
	while(l == P && l!=0){
		l = nrz(c--);
	}
	if(l == 0) return cout << 1,0;
	return cout << c+2,0;
	}
	}
	return cout << "-1",0;
}