Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* package codechef; // don't place package name! */
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- /* Name of the class has to be "Main" only if the class is public. */
- public class Main
- {
- public static void main (String[] args) throws java.lang.Exception
- {
- Scanner scanner = new Scanner(System.in);
- int T = scanner.nextInt();
- for (int j = 0; j < T; j++) {
- int N = scanner.nextInt();
- int a = 0;
- int[] arr = new int[N];
- for (int i = 0; i < N; i++) {
- arr[i] = scanner.nextInt();
- }
- int[] cnt = new int[4];
- for (int i = 0; i < 4; i++) {
- cnt[i] = 0;
- }
- for (int i = 0; i < N; i++) {
- cnt[arr[i] % 4]++;
- }
- a += (cnt[0] * (cnt[0] - 1)) / 2;
- for (int i = 1; i <= ((4 / 2) - 1); i++) {
- a += cnt[i] * cnt[4 - i];
- }
- if (4 % 2 == 0) {
- a += (cnt[4 / 2] * (cnt[4 / 2] - 1)) / 2;
- }
- System.out.println(a);
- }
- scanner. Close();
- }
- }
Add Comment
Please, Sign In to add comment