GokulDeep

div Count

Dec 17th, 2023 (edited)
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | Source Code | 0 0
  1. /* package codechef; // don't place package name! */
  2. import java.util.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. /* Name of the class has to be "Main" only if the class is public. */
  7. public class Main
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. Scanner scanner = new Scanner(System.in);
  12.  
  13. int T = scanner.nextInt();
  14. for (int j = 0; j < T; j++) {
  15.  
  16. int N = scanner.nextInt();
  17.  
  18. int a = 0;
  19.  
  20. int[] arr = new int[N];
  21.  
  22. for (int i = 0; i < N; i++) {
  23. arr[i] = scanner.nextInt();
  24. }
  25.  
  26. int[] cnt = new int[4];
  27.  
  28. for (int i = 0; i < 4; i++) {
  29. cnt[i] = 0;
  30. }
  31.  
  32. for (int i = 0; i < N; i++) {
  33. cnt[arr[i] % 4]++;
  34. }
  35.  
  36. a += (cnt[0] * (cnt[0] - 1)) / 2;
  37.  
  38.  
  39. for (int i = 1; i <= ((4 / 2) - 1); i++) {
  40. a += cnt[i] * cnt[4 - i];
  41. }
  42.  
  43. if (4 % 2 == 0) {
  44. a += (cnt[4 / 2] * (cnt[4 / 2] - 1)) / 2;
  45. }
  46. System.out.println(a);
  47. }
  48. scanner. Close();
  49. }
  50. }
Tags: JavaPPA
Add Comment
Please, Sign In to add comment