int main()
{
    Init();
    int t, n, cas = 0;
    scanf("%d", &t);
    while (t--){
        scanf("%d", &n);
        for (int i = 0; i < MAX; ++i) in[i] = -1;
        for (int i = 0; i < n; ++i){
            scanf("%d", &arr[i]);
            in[arr[i]] = i;
        }
        g.Init(n+2);
        int S = n, T = n+1;
        for (int i = 0; i < n; ++i){
            int x = arr[i];
            if (cnt[x]&1) g.Addedge(S, i, 1);
            else g.Addedge(i, T, 1);
//            else{
//                printf("Not Prime %d\n", x);
                for (int j = 0; j < tot && prime[j] <= x; ++j){
                    if (x%prime[j]) continue;
//                    printf("x = %d factor = %d\n", x, prime[j]);
                    int y = x/prime[j];
                    if (in[y] != -1){
                        int v = in[y];
                        if (cnt[x]&1) g.Addedge(i, v, 1);
                        else g.Addedge(v, i, 1);
                    }
                    if (y > prime[tot-1] && cnt[y] == 1){
                        y = prime[j];
                        if (in[y] != -1){
                            int v = in[y];
                            if (cnt[x]&1) g.Addedge(i, v, 1);
                            else g.Addedge(v, i, 1);
                        }
                    }
                }
//            }
//            if (!flag && in[1] != -1) g.Addedge(i, in[1], 1);
        }
        printf("Case %d: %d\n", ++cas, n-g.Maxflow(S, T));
    }
    return 0;
}
Exemplo n.º 2
0
void proc() {
    scanf("%d %d %d", &n, &m, &c);
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        graph[a].push_back(Edge{ c, b });
        graph[b].push_back(Edge{ c, a });
    }
 
    for (int i = 1; i <= n; ++i) {
        dist[i] = 100000000;
    }
    priority_queue<Edge> pq;
    dist[1] = 0;
    pq.push(Edge{ 0, 1 });
    while (!pq.empty()) {
        Edge cur = pq.top();
        pq.pop();
        if (cur.w > dist[cur.to]) {
            continue;
        }
        for (const auto& edge : graph[cur.to]) {
            if (dist[edge.to] > dist[cur.to] + edge.w) {
                dist[edge.to] = dist[cur.to] + edge.w;
                pq.push(Edge{ dist[edge.to], edge.to });
                via[edge.to].clear();
                via[edge.to].push_back(cur.to);
            }
            else if (dist[edge.to] == dist[cur.to] + edge.w) {
                via[edge.to].push_back(cur.to);
            }
        }
    }
 
    for (int i = 0; i < c; ++i) {
        int v;
        scanf("%d", &v);
        carInit.push_back({ dist[v], v });
    }
    sort(carInit.begin(), carInit.end());
 
    MaxFlow mf;
    mf.Init(n + c + 2);
    for (int k = 1; k <= n; ++k) {
        for (int v : via[k]) {
            mf.AddEdge(k, v, 1);
        }
    }
    int ans = 0;
    for (int i = 0; i < carInit.size(); ) {
        mf.ClearFlow();
        int ss = n + 1 + i;
 
        int j = i;
        while (j < carInit.size() && carInit[i].first == carInit[j].first) {
            int k = j, cnt = 0;
            while (k < carInit.size() && carInit[j].second == carInit[k].second) {
                ++k;
                ++cnt;
            }
            mf.AddEdge(ss, carInit[j].second, cnt);
            j = k;
        }
        ans += mf.Solve(ss, 1);
 
        i = j;
    }
    printf("%d", ans);
}