fork download
  1. #include <iostream>
  2. using namespace std;
  3. int count(int arr[],int n,int k){
  4. int count;
  5. int sum=0;
  6. for(int i=0;i<n;i++){
  7. count=0;
  8. for(int j=i;j<n;j++){
  9. sum+=arr[j];
  10. if(sum%k==j-i+1){
  11. count++;
  12. }
  13. }
  14. }
  15. return count;
  16. }
  17.  
  18. int main() {
  19. // your code goes here
  20. int n;
  21. cin>>n;
  22. int k;
  23. cin>>k;
  24. int arr[n];
  25. for(int i=0;i<n;i++){
  26. cin>>arr[i];
  27. }
  28. cout<<"The count of good subarrays is:"<<count(arr,n,k);
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5324KB
stdin
4
1 3 2 4
4
stdout
The count of good subarrays is:0