CHANPAIR - Editorial

Problem Link:

Practice
Author: Sakchi Agarwal
Author: Sparsh Kedia
Editorialist: Ayush Shukla

DIFFICULTY:

Cakewalk

PREREQUISITES:

Basic Mathematics

PROBLEM:

You are given an array of N elements. Each element of the array is prime. Find the number of pairs that can be formed such that difference of the elements of the pair is odd.

QUICK EXPLANATION:

The one element of pair must be even. And we have only one even prime number, i.e. , 2.

EXPLANATION:

We know that total number of element in array is N. Lets keep count of number 2 in array, denoted as, count.
Now the total number of pair such that their difference is an odd number is (count)*(N-count).

Setter's Solution
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{   ll t;
    cin >> t;
    
    while (t--)
    {
      ll n;
      cin>>n;
      ll a[n];
      ll count=0;
      for(ll i=0;i<n;i++)
      {
          cin>>a[i];
          if(a[i]%2==0)count++; //a[i] is 2
          
      }
      cout<<count*(n-count)<<endl;
    }
 
    return 0;
} 
Tester's Solution
import math
t = int(input())
while t>0 : 
	n = int(input())
	cnt2 = 0
	l = input().split()
	for i in range(0,n):
	    if(l[i]=='2'):
	        cnt2+=1
	        
	print((n-cnt2)*cnt2)
	t = t-1 

Feel free to share your approach. :slight_smile: Happy Coding :slight_smile: