Cod sursa(job #2736040)

Utilizator vansJos da pa perete vans Data 3 aprilie 2021 09:29:56
Problema Economie Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <bits/stdc++.h>

using namespace std;

const int NMAX = 1000, NRMAX = 5e4;

int n, a[NMAX + 1], fr[NRMAX + 1];
bool notOk[NRMAX + 1];
set<int> st;

int main()
{
    freopen("economie.in", "r", stdin);
    freopen("economie.out", "w", stdout);
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]), ++fr[a[i]];
    }
    int cnt = 0;
    sort(a + 1, a + n + 1);
    for(int i = 1; i <= n; ++i)
        if(!notOk[a[i]]) {
            int crt = 0;
            for(int j = a[i]; j <= NRMAX; j += a[i])
                notOk[j] = 1,
                crt += fr[j], fr[j] = 0;
            if(crt) st.insert(i), cnt += crt;
        }
    printf("%d\n", (int)st.size());
    for(const auto &el : st) printf("%d\n", el);
    return 0;
}