Cod sursa(job #718597)

Utilizator stefi1234stefi ristea stefi1234 Data 20 martie 2012 21:57:48
Problema Factoriale Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 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[50],b[50];
	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[100],dim;
	cif[0]=1;
	dim=1;
	for(i=0;i<50;i++)
		if((a[i]<k)&&(a[i]>0))
			while(a[i]<k)
			{
				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;
}