`{"id":"553ffabc-16d0-4fd7-9532-7cc5fabc07a9","name":"Count Of Subarrays With Sum Divisible By K","description":"1. You are given an array of integers(arr) and a number K.\r\n2. You have to find the count of subarrays whose sum is divisible by K.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers\r\nA number K","outputFormat":"A number representing the count of subarrays whose sum is divisible by K.","constraints":"1 &lt;= N,K &lt;= 10^5\r\n-1000 &lt;= arr[i] &lt;= 1000","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nint solution(vector<int> arr, int k) {\n // write your code here\n}\n\n\n\nint main(){\n int n;\n cin >> n;\n vector<int> arr(n);\n for (int i = 0; i < n; i++) {\n cin >> arr[i];\n }\n int k;\n cin >> k;\n cout << solution(arr, k);\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int solution(int[] arr, int k) {\r\n // write your code here\r\n\r\n return 0;\r\n }\r\n \r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n int k = scn.nextInt();\r\n System.out.println(solution(arr, k));\r\n }\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n2 7 6 1 4 5\r\n3","sampleOutput":"5\r\n","questionVideo":"https://www.youtube.com/embed/QM0klnvTQzk?end=13","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"e1c64c46-93a4-415c-8b61-7ef3eea702bf","name":"Count Of Subarrays With Sum Divisible By K","slug":"count-of-subarrays-with-sum-divisible-by-k","type":1}],"next":{"id":"60ec54cd-8a0c-4450-b07e-fb9873810372","name":"Count Of Subarrays With Sum Divisible By K MCQ","type":0,"slug":"count-of-subarrays-with-sum-divisible-by-k-mcq"},"prev":{"id":"3d125e14-1420-470e-8726-6381a5147bae","name":"Longest Subarray With Sum Divisible By K","type":3,"slug":"longest-subarray-with-sum-divisible-by-k"}}}`

Count Of Subarrays With Sum Divisible By K

1. You are given an array of integers(arr) and a number K. 2. You have to find the count of subarrays whose sum is divisible by K.

`{"id":"553ffabc-16d0-4fd7-9532-7cc5fabc07a9","name":"Count Of Subarrays With Sum Divisible By K","description":"1. You are given an array of integers(arr) and a number K.\r\n2. You have to find the count of subarrays whose sum is divisible by K.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers\r\nA number K","outputFormat":"A number representing the count of subarrays whose sum is divisible by K.","constraints":"1 &lt;= N,K &lt;= 10^5\r\n-1000 &lt;= arr[i] &lt;= 1000","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nint solution(vector<int> arr, int k) {\n // write your code here\n}\n\n\n\nint main(){\n int n;\n cin >> n;\n vector<int> arr(n);\n for (int i = 0; i < n; i++) {\n cin >> arr[i];\n }\n int k;\n cin >> k;\n cout << solution(arr, k);\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int solution(int[] arr, int k) {\r\n // write your code here\r\n\r\n return 0;\r\n }\r\n \r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n int k = scn.nextInt();\r\n System.out.println(solution(arr, k));\r\n }\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n2 7 6 1 4 5\r\n3","sampleOutput":"5\r\n","questionVideo":"https://www.youtube.com/embed/QM0klnvTQzk?end=13","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"e1c64c46-93a4-415c-8b61-7ef3eea702bf","name":"Count Of Subarrays With Sum Divisible By K","slug":"count-of-subarrays-with-sum-divisible-by-k","type":1}],"next":{"id":"60ec54cd-8a0c-4450-b07e-fb9873810372","name":"Count Of Subarrays With Sum Divisible By K MCQ","type":0,"slug":"count-of-subarrays-with-sum-divisible-by-k-mcq"},"prev":{"id":"3d125e14-1420-470e-8726-6381a5147bae","name":"Longest Subarray With Sum Divisible By K","type":3,"slug":"longest-subarray-with-sum-divisible-by-k"}}}`

Editor

Count Of Subarrays With Sum Divisible By K

easy

1. You are given an array of integers(arr) and a number K. 2. You have to find the count of subarrays whose sum is divisible by K.

Constraints

1 <= N,K <= 10^5 -1000 <= arr[i] <= 1000

Format

Input

A number N arr1 arr2.. N numbers A number K

Output

A number representing the count of subarrays whose sum is divisible by K.

Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}6 2 7 6 1 4 5 3```

Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}5 ```

Question Video

Discussions

Show Discussion

Related Resources