You are viewing a single comment's thread. Return to all comments →
Scanner sc = new Scanner(System.in); int size = sc.nextInt();
for(int l = 0; l < size; l++) { int n = sc.nextInt(); int k = sc.nextInt(); long[] numbers = new long[n]; for(int i = 0; i < n; i++) { numbers[i] = sc.nextLong(); } long[] prefixModCount = new long[k]; for(int i = 0; i < k; i++) { prefixModCount[i] = 0; } prefixModCount[0] = 1; int prefixSum = 0; for(int i = 0; i < numbers.length; i++) { prefixSum += numbers[i]; prefixSum %= k; prefixModCount[prefixSum] += 1; } long result = 0; for(int mod = 0; mod < k; mod++) { result += prefixModCount[mod] * (prefixModCount[mod] - 1) / 2; } System.out.println(result); }
Consecutive Subsequences
You are viewing a single comment's thread. Return to all comments →
Scanner sc = new Scanner(System.in); int size = sc.nextInt();