Pagini recente » Cod sursa (job #718937) | Cod sursa (job #3240937) | Cod sursa (job #1935035) | Cod sursa (job #2332966) | Cod sursa (job #277431)
Cod sursa(job #277431)
#include <stdio.h>
#define DIM 101
int a[DIM],set[DIM],v[50*DIM];
int n,i,ok,k,max,j,w,aux,x;
FILE *f = fopen("economie.in", "r");
FILE *g = fopen("economie.out", "w");
int main(){
fscanf(f,"%d",&n);
for (i=1; i<=n; i++)
fscanf(f,"%d",&a[i]);
do {
ok = 0;
for (i=1; i<n; i++)
if (a[i] > a[i+1]) {
aux = a[i];
a[i] = a[i+1];
a[i+1] = aux;
ok = 1;
}
} while (ok);
max = a[n];
for (i=1; i<=n; i++)
if (v[a[i]]==0) {
set[++k] = a[i];
j = 1;
w = a[i];
while (w*j <= max) {
v[w*j] = 1;
j++;
}
for (x=1; x<k; x++) {
j = 1;
w = set[x]+set[k];
while (w*j <= max) {
v[w*j] = 1;
j++;
}
}
}
fprintf(g,"%d\n",k);
for (i=1; i<=k; i++)
fprintf(g,"%d\n",set[k]);
fclose(f);
fclose(g);
return 0;
}