Pagini recente » Cod sursa (job #2693710) | Cod sursa (job #3211604) | Cod sursa (job #2061911) | Cod sursa (job #2351602) | Cod sursa (job #3163854)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("economie.in");
ofstream fout("economie.out");
const int DIM = 1010;
const int MAX = 50010;
int n;
int v[DIM];
bool visited[MAX], isSol[MAX];
int main() {
fin >> n;
for (int i = 1; i <= n; i++)
fin >> v[i];
sort(v + 1, v + n + 1);
int solCnt = 0;
visited[0] = true;
for (int i = 1; i <= n; i++) {
bool hasVisited = false;
for (int j = i; j <= n; j++) {
if (visited[v[j] % v[i]] && !visited[v[j]])
visited[v[j]] = hasVisited = true;
}
if (hasVisited) {
solCnt++;
isSol[i] = true;
}
}
fout << solCnt << '\n';
for (int i = 1; i <= n; i++)
if (isSol[i])
fout << v[i] << ' ';
return 0;
}