Cod sursa(job #2990388)

Utilizator raresgherasaRares Gherasa raresgherasa Data 7 martie 2023 20:53:53
Problema Economie Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#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';
   }
}