Cod sursa(job #2559436)

Utilizator raizoSoare Antonio raizo Data 27 februarie 2020 12:26:33
Problema Factorial Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");

int power( int base, int exp);
long long int factorial(int n);

int main() {
	long long int p, n, f, op;
	in >> p;

	/*if (p > 0) { out << p * 5; }
	else if (p == 0) { out << 1; }
	else { out << -1; }
	*/

	op = power(10, p);

	n = 1;
	f = factorial(n);

	while (f % op != 0) {
		n++;
		f = factorial(n);

	}

	if (n >= 1) { out << n; }
	else{ out << -1;}

	return 0;

}

int power(int base, int exp) {
	int result = 1;
	for (int c = 1;c <=exp;c++) {
		result = result * base;
	}
	return result;

}


	long long int factorial(int n) {
		if (n > 0) { return(n * factorial(n - 1)); }
		else return 1;

	}