Sherlock and XOR

QUESTION

You are given an array A1,A2…AN. You have to tell how many pairs (i, j) exist such that 1<= i < j <= N and Ai XOR Aj is odd.\n\nInput and Output \n\nFirst line T, the number of test cases. Each test case: first line N, followed by N integers in next line. For each test case, print the required answer in one line.\n\nConstraints \n1<= T <= 10 \n1 <= N <= 10^5 \n0 <= Ai <= 10^9.

ANSWER

#include <iostream>
using namespace std;
int main()
{
    int t;
    std::cin>>t;
    while(t--)
    {
        long long n;
        std::cin>>n;
        long long arr[n];
        for(int i=0;i<n;i++)
        {
            std::cin>>arr[i];
        }
        long long o=0,e=0;
        for(int i=0;i<n;i++)
        {
            if(arr[i]%2==0)
            {
                e++;
            }
            else
            {
                o++;
            }
        }
        std::cout<<o*e<<"\n";
    }
    return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro