Cod sursa(job #586378)

Utilizator xaphariusMihai Suteu xapharius Data 30 aprilie 2011 17:52:14
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <cstdio>

void getprims(int x, int &_count2, int &_count5){
	_count2 = _count5 = 0;
	//check 2
	while (x && !(x & 1)){
		x >>= 1;
		++_count2;
		
	}
	while (x % 5 == 0){
		x /= 5;
		++_count5;
	}
}

int main(){
	freopen("fact.in", "r", stdin);
	freopen("fact.out", "w", stdout);
	
	int P;
	scanf("%d", &P);

	int i = 0, count0 = 0, count2 = 0, count5 = 0;
	int _count2, _count5;
	while (count0 < P){
		++i;
		getprims(i, _count2, _count5);
		count2 += _count2;
		count5 += _count5;
		count0 = count2 < count5? count2 : count5;
	}
	
	if (count0 == P) printf("%d", i);
	else printf("-1");

	return 0;
}