Pagini recente » Cod sursa (job #215052) | Cod sursa (job #2274162) | Cod sursa (job #2742531) | Cod sursa (job #1216517) | Cod sursa (job #277534)
Cod sursa(job #277534)
#include <stdio.h>
#define DIM 1001
int a[DIM],set[DIM],v[50002];
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 = 2;
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++;
}
}
}
else {
for (x=1; x<n; x++) {
j = 1;
w = a[x]+a[i];
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[i]);
fclose(f);
fclose(g);
return 0;
}