Cod sursa(job #300283)

Utilizator toni2007Pripoae Teodor Anton toni2007 Data 7 aprilie 2009 12:41:57
Problema Factoriale Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <cstdio>
#define maxN	128
#define maxCIF 	100000
int Nr[maxN], X[maxN], N, K, Sol[maxCIF];

void mul (int A[], int B) {
	int i, t = 0;
	for (i = 1; i <= A[0] || t; ++ i, t /= 10)
		A[i] = (t += A[i] * B) % 10;
	A[0] = i - 1;
}

int main () {
	int i, j, k, now;

	freopen("factoriale.in", "r", stdin);
	freopen("factoriale.out", "w", stdout);

	scanf("%d%d", &N, &K);

	for (i = 1; i <= N; ++ i)
		scanf("%d", &X[i]);

	for (i = 1; i <= N; ++ i) {
		for (k = 2; k <= X[i]; ++ k) {
			now = k;
			for (j = 2; now > 1 && j <= now; ++ j)
				while (now % j == 0) {
					++ Nr[j];
					now /= j;
				}
		}
	}
//	for (i = 1; i <= 10; ++ i)
//		printf("%d ", Nr[i]);
	
	Sol[0] = Sol[1] = 1;

	for (i = 2; i <= 100; ++ i)
		while (Nr[i] % K != 0) {
			Nr[i] ++;
			mul (Sol, i);
		}

	for (i = Sol[0]; i; -- i)
		printf("%d", Sol[i]);
}