Cod sursa(job #718631)

Utilizator 5t3fristea stefan 5t3f Data 20 martie 2012 22:21:08
Problema Factoriale Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
// factoriale5.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include "fstream"
using namespace std;
int main()
{
	ifstream f("factoriale.in");
	ofstream g("factoriale.out");
	int n,k,a[100],b[100];
	int i;
	f>>n>>k;
	for(i=0;i<50;i++)
	{
		a[i]=0;
		b[i]=0;
	};
	for(i=0;i<n;i++)
	{
		int tmp,tmp2;
		f>>tmp;
		int j;
		for(j=2;j<=tmp;j++)
		{
			int l;
			tmp2=j;
			for(l=2;l<=j;l++)
				while(tmp2%l==0)
				{
					a[l]++;
					tmp2/=l;
				}
		}
	}
	int cif[100000],dim;
	cif[0]=1;
	dim=1;
	for(i=0;i<50;i++)
	if(a[i]!=0)
	{
		int tmp=a[i];
		int tmp2=k;
		if(a[i]%k!=0)
			while(a[i]!=k)
			{
				if(a[i]>k)
					a[i]-=k;
				if(a[i]<k)
					k-=a[i];
			}
		int nr;
		nr=(tmp*tmp2)/(a[i]);
		k=tmp2;
		a[i]=tmp;
		int l;
		for(l=0;l<nr;l++)
			{
				if(a[i]%k==0)
					break;
				int j;
				for(j=0;j<dim;j++)
					cif[j]*=i;
				for(j=dim-1;j>0;j--)
					if(cif[j]>9)
					{
						cif[j-1]+=cif[j]/10;
						cif[j]%=10;
					}
				if(cif[0]>9)
				{
					for(j=dim;j>0;j--)
						cif[j]=cif[j-1];
				cif[1]=cif[0]%10;
				cif[0]/=10;
				dim++;
				}
				a[i]++;
			}
	}
	for(i=0;i<dim;i++)
		g<<cif[i];
	return 0;
}