Cod sursa(job #146943)

Utilizator AndreyPAndrei Poenaru AndreyP Data 2 martie 2008 14:01:43
Problema Factoriale Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include<stdio.h>
int c[101];
int main()
{
	freopen("factoriale.in","r",stdin);
	freopen("factoriale.out","w",stdout);
	int p[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	int n,k,x,i,j,t,w,r=1,xmax=0;
	scanf("%d%d",&n,&k);
	for(i=0; i<n; i++)
	{
		scanf("%d",&x);
		if(x>xmax)
			xmax=x;
		for(j=2; j<=x; j++)
		{
			w=j;
			for(t=0; (t<25)&&(w!=1); t++)
			{
				while(w%p[t]==0)
				{
					w=w/p[t];
					c[p[t]]++;
				}
			}
		}
	}
	for(i=2; i<=xmax; i++)
	{
		if(c[i])
		{
			if(i%k!=0)
			{
				for(j=k-i%k; j>0; j--)
					r*=i;
			}
		}
	}
	printf("%d\n",r);
	return 0;
}