Cod sursa(job #503980)

Utilizator mihaipopa12Popa Mihai mihaipopa12 Data 25 noiembrie 2010 23:46:22
Problema Factoriale Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include<stdio.h>

#define DIM 55

FILE*f=fopen("factoriale.in","r");
FILE*g=fopen("factoriale.out","w");

int N,K,p,PR[DIM],i,j,X,putere[DIM],x,R;
char V[105];
int REZ[1000];

void inmult ( int A[], int X ){
	
	int T = 0;
	for ( i = 1 ; i <= A[0] ; ++i ){
		A[i] = A[i] * X + T ;
		T = A[i] / 10;
		A[i] = A[i] % 10;
	}
	
	while ( T ){
		A[++A[0]] = T % 10;
		T /= 10;
	}
	
}

void ciur(){
	
	for ( int i = 2 ; i <= 100 ; ++i ){
		if ( !V[i] ){
			for ( int j = i + i ; j <= 100 ; j += i )
				V[j] = 1;
			PR[++p] = i;
		}
	}
	
}

int main () {
	
	fscanf(f,"%d %d",&N,&K);
	
	ciur();
	
	for ( i = 1 ; i <= N ; ++i ){
		fscanf(f,"%d",&X);
		for ( j = 1 ; j <= p && PR[j] <= X; ++j ){
			x = PR[j];
			while ( x <= X ){
				putere[j] += X / x;
				x = PR[j] * x;
			}
		}
	}
	REZ[0] = REZ[1] = 1;
	for ( j = 1 ; j <= p ; ++j ){
		
		if ( putere[j] != 0 ){
			while ( putere[j] % K != 0 ){
				inmult(REZ,PR[j]);
				++putere[j];
			}
			
		}
		
	}
	
	for ( i = REZ[0] ; i >= 1 ; --i )
		fprintf(g,"%d",REZ[i]);
	fprintf(g,"\n");
	
	fclose(f);
	fclose(g);
	
	return 0;
}