Subarray Problem

#include
using namespace std;
int main() {
int t;
cin>>t;
int count=0;
int sum;
while(t<0)
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
sum=0;
for(int k=i;k<=j;k++)
{
sum=sum+arr[k];
if(sum%n==0)
{
count++;
}
}
}
}
cout<<count<<endl;
t–;
}
return 0;
}
tell me the problem in the code.

@Aryanomar00 Hey Aryan, Please correct below Mistake

  1. while(t < 0 ) --------------> while(t > 0)
  2. Initialize count = 0 in every iteration of t.
  3. if(sum%n == 0) --------------> This if block comes after ending of k loop.

Time limit exceeded for the second test came.

#include using namespace std; int main() { int t; cin>>t; int count; int sum; while(t>0) { count=0; int n; cin>>n; int arr[n]; for(int i=0;i<n;i++) { cin>>arr[i]; } for(int i=0;i<n;i++) { for(int j=i;j<n;j++) { sum=0; for(int k=i;k<=j;k++) { sum=sum+arr[k]; } if(sum%n==0) { count++; } } } cout<<count<<endl; t–; } return 0; }

can you please tell me the mistake in the code…

@Aryanomar00 Hey Aryan, Please refer CPP - Divisble Subarrays, Pigeonhole Problem which is in the section of Number theory Basics.