Segmentation fault for larger test cases

Getting segmentation fault for larger test cases with unknown input.
Submission got partially correct with 15/300 points…
Can someone help me finding the mistake or a test case where this error can come.

int factors(int A)

{
int fac=2, facmul=1,i;
for(i=2;ii<=A;i++)
{
if(A%i==0)
fac = (i
i)==A?(fac+1):(fac+2);
}
if(fac%2!=0)
{
facmul=facmul*(i-1);
}
for(int i=1;i<=fac/2;i++)
{
facmul = ((long long int)facmul*(long long int)A)%1000000007;
}
return facmul;
}
int mycompare(vector A, vector B)
{
return (A[0]>B[0])?1:0;
}
int binary(vector<vector> &A,int q, int l, int r)
{
int mid;
while(l<=r)
{
mid=(l+r)/2;
if(A[mid][1]==q)
return mid;
else if(A[mid][1]>q)
r=mid-1;
else
l=mid+1;
}
return r+1;
}
vector Solution::solve(vector &A, vector &B) {
int n = A.size(),m=B.size(),idx,j;
vector ans(m);
vector Al(n),Ar(n);

Al[0]=-1;
for(int i=1;i<n;i++)
{
j=i-1;
while(A[i]>A[j])
{
j=Al[j];
if(j<0)
break;
}
Al[i]=j;
}

Ar[n-1]=n;
for(int i=n-2;i>=0;i–)
{
j=i+1;
while(A[i]>=A[j])
{
j=Ar[j];
if(j>=n)
break;
}
Ar[i]=j;
}

vector<vector> temp(n,vector(2));
for(int i=0;i<n;i++)
{
//cout<<i<<" “;
//cout<<A[i]<<”:"<<Al[i]<<":"<<Ar[i]<<" “;
temp[i][0]=factors(A[i]);
temp[i][1]=((long long int)(i-Al[i]))*((long long int)(Ar[i]-i));
//cout<<temp[i][0]<<”:"<<temp[i][1]<<endl;
}

//cout<<temp[0][0]<<":"<<temp[0][1]<<" “;
sort(temp.begin(),temp.end(),mycompare);
//cout<<temp[0][0]<<”:"<<temp[0][1]<<" ";

for(int i=1;i<n;i++)
{
//cout<<temp[i][0]<<":"<<temp[i][1]<<" “;
temp[i][1]=temp[i][1]+temp[i-1][1];
//cout<<temp[i][0]<<”:"<<temp[i][1]<<" ";
}

//cout<<endl;
for(int i=0;i<m;i++)
{
idx=binary(temp,B[i],0,n-1);
//cout<<B[i]<<":"<<idx<<endl;
ans[i]=temp[idx][0];
}

return ans;
}

do not forget taking modulo with 1000000007

Click here to start solving coding interview questions