Cod sursa(job #2739651)

Utilizator JumpingIntoTheVoidDavid Petreanu JumpingIntoTheVoid Data 9 aprilie 2021 03:44:22
Problema Factorial Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
#include <iostream>

int p, c=1;
long long int factorial = 1;
bool gasit = false;

int nrzero(int x) {
	int c = 0; bool ok = true;
	while (x) {
		if (x % 10 == 0) { 
			c++;
		}
		else {
			ok = false;
		}
		if (ok == false) {
			break;
		}
		x /= 10;
	}
	return c;
}


int main() {
    std::ifstream fin("fact.in");
    std::ofstream fout("fact.out");
	fin >> p;
	if (p == 0) {
		fout << 1;
	}
	else {
		while (factorial < 999999999999999) {
			factorial = 1;
			for (int i = 1; i <= c; i++) {
				factorial *= i;
			}
			if (nrzero(factorial) == p) {
				fout << c;
				gasit = true;
				break;
			}
			c++;
		}
		if (gasit == false) fout << -1;
	}
}