Cod sursa(job #970614)

Utilizator danlexDan Alexandru danlex Data 7 iulie 2013 14:36:45
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <iostream>
#include <fstream>
using namespace std;

long long z, n;
bool DEBUG = false;

void print(){
	cout << "z: " << z <<  " n: " << n << endl;
}

void read(){
    ifstream fi("fact.in");
    fi >> z;
    fi.close();
}

void write(){
    ofstream fo("fact.out");
    fo << n;
    fo.close();
}

long long zeroN(long long n){
	long long z = 0;
    while (n/5!=0) {
        z += n / 5;
        n = n / 5;
    }
    return z;
}

long long findN(long long estStart, long long estEnd){
	if (estEnd == 0){
		return 1;
	}
	if (estEnd - estStart < 2){
		return -1;
	}
	int estMidd = estStart + (estEnd - estStart) / 2;
	int estZ = zeroN(estMidd);
	if (estZ < z){
		return findN(estMidd, estEnd);
	} else if (estZ > z){
		return findN(estStart, estMidd);
	} else {
		estMidd -= estMidd % 5;
		return estMidd;
	}
}

void compute(){
	long long estStart = 4 * z;
	long long estEnd = 6 * z;
	n = findN(estStart, estEnd);
	if(DEBUG) print();
}

int main(void){
    read();
    compute();
	write();
    return 0;
}