Cod sursa(job #526774)

Utilizator tudorsTudor Siminic tudors Data 29 ianuarie 2011 13:38:23
Problema Economie Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
#define ma 50001
int n,i,k,j,r;
int V[ma],A[ma],REZ[ma];
int x;

ifstream f("economie.in");
ofstream g("economie.out");

int main()
{
	f>>n;
	for (i=1;i<=n;i++)
		f>>A[i];
	sort(A+1,A+n+1);
	r=0;
	r++;
	REZ[r]=A[1];
	j=A[1];
	while (j<=ma)
	{
		V[j]=1;
		j+=A[1];
	}
	for (i=2;i<=n;i++)
	{
		if (!V[A[i]])
		{
			r++;
			REZ[r]=A[i];
			j=1;
			while (j<=ma)
			{
				if (j%A[i]==0)
					V[j]=1;
				if (V[j]==1)
					V[j+A[i]]=1;
				j++;
			}
		}
	}
	g<<r<<endl;
	for (i=1;i<=r;i++)
		g<<REZ[i]<<endl;
	f.close();
	g.close();
	return 0;
}