Cod sursa(job #134132)

Utilizator AndreyPAndrei Poenaru AndreyP Data 10 februarie 2008 18:49:40
Problema Economie Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include<stdio.h>
#include<stdlib.h>
int v[1002],af[1002];
char c[50001];
/*int compar(const void *p,const void *q)
{
	int *pp=(int*)p,*qq=(int*)q;
	int a=*pp,b=*qq;
	if(a<b)
		return -1;
	if(a>b)
		return 1;
	return 0;
}*/
int main()
{
	int n,i,min=0,j,max,x;
	freopen("economie.in","r",stdin);
	freopen("economie.out","w",stdout);
	scanf("%d",&n);
	for(i=0; i<n; i++)
		scanf("%d",&v[i]);
	//qsort(v,n,sizeof(v[0]),compar);
	if(v[0]==1)
	{
		printf("1\n1\n");
	}
	else
	{
		min=1;
		af[1]=v[0];
		max=v[n-1];
		x=v[0];
		while(x<=max)
		{
			c[x]=1;
			x+=v[0];
		}
		for(i=1; i<n; i++)
		{
			if(c[v[i]]==0)
			{
				min++;
				af[min]=v[i];
				c[v[i]]=1;
				for(j=1; j<=max; j++)
				{
					if(c[j])
					{
						x=v[i];
						while(x+j<=max)
						{
							c[x+j]=1;
							x+=v[i];
						}
					}
				}
				/*x=v[i];
				while(x<=max)
				{
					c[x]=1;
					x+=v[i];
				}*/
			}
		}
		printf("%d\n",min);
		for(i=1; i<=min; i++)
			printf("%d\n",af[i]);
	}
	return 0;
}