Binary Parity I Codechef Solution || Codechef contest solution

#include <iostream>
using namespace std;

string findBinaryParity(int N) {
    // Count the number of set bits in N
    int count = 0;
    while (N) {
        count += N & 1;
        N >>= 1;
    }

    // Check if the count is even or odd
    if (count % 2 == 0) {
        return "EVEN";
    } else {
        return "ODD";
    }
}

int main() {
    int T;
    cin >> T;

    while (T--) {
        int N;
        cin >> N;

        cout << findBinaryParity(N) << endl;
    }

    return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *