Pagini recente » Istoria paginii utilizator/david_rodica_mihaela_324ca | Profil Razvan48 | Cod sursa (job #2990388)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("economie.in");
ofstream fout ("economie.out");
const int N_MAX = 5e4 + 5;
int n;
int a[N_MAX], dp[N_MAX];
vector<int>used, v;
int main(){
ios_base::sync_with_stdio(false);
fin >> n;
for (int i = 1; i <= n; i++){
fin >> a[i];
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++){
if (!dp[a[i]]){
used.push_back(a[i]);
int x = a[i];
while (x < N_MAX){
dp[x] = true;
x += a[i];
}
}
}
fout << (int)used.size() << '\n';
for (int x : used){
fout << x << '\n';
}
}