1586A - Windblume Ode - CodeForces Solution


brute force constructive algorithms greedy math number theory *800

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template <typename... Args>
void print(const Args&... arg) {
    ((cout << arg), ...);
}
void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    int sum = 0;
    for (int i = 1; i <= n; i++)  {
        cin >> a[i];
        sum += a[i];
    }
    int ok = 0;
    for (int i = 2; i <= sum/i; i++) {
        if (sum % i == 0) ok = 1;
    }
    if (ok) {
        print(n, '\n');
        for (int i = 1; i <= n; i++) {
            print(i, " \n"[i == n]);
        }
    }else {
        print(n - 1, '\n');
        for (int i = 1; i <= n; i++) {
            if (ok || a[i] % 2 == 0) print(i, ' ');
            else if (a[i] % 2) ok = 1;
        }
        print("\n");
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return (0*0);
}


Comments

Submit
0 Comments
More Questions

1692B - All Distinct
1156C - Match Points
1675A - Food for Animals
1328C - Ternary XOR
1689A - Lex String
1708B - Difference of GCDs
863A - Quasi-palindrome
1478A - Nezzar and Colorful Balls
1581B - Diameter of Graph
404A - Valera and X
908A - New Year and Counting Cards
146A - Lucky Ticket
1594C - Make Them Equal
1676A - Lucky
1700B - Palindromic Numbers
702C - Cellular Network
1672C - Unequal Array
1706C - Qpwoeirut And The City
1697A - Parkway Walk
1505B - DMCA
478B - Random Teams
1705C - Mark and His Unfinished Essay
1401C - Mere Array
1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats
1703A - YES or YES