Cod sursa(job #1105680)

Utilizator s1mpMihai Alexandru s1mp Data 11 februarie 2014 23:23:51
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include<iostream>
#include<fstream>

using namespace std;

long P;

int main() {
	ifstream f("fact.in");
	ofstream g("fact.out");
	f>>P;
	long N = 4 * P;
	long k = 0;
	long y = 5;
	long i = 0;
	while (N/y > 0) {
		k += N/y;
		y *= 5;
	}
	if (k < P) {
		for(i = N+1; i <= P*5 && k < P; i++) {
			y = i;
			while (y % 5 == 0) {
				k++;
				y /= 5;
			}
		}
	}
	if (P == 0) {
		g<<1;
	} else if (k == P) {
		g<<i-1;
	} else {
		g<<-1;
	}
		
	f.close();
	g.close();
	return 0;
}