Wrong answer for larger test cases in c++


#1
    long long productDivisors(long long N){
vector<long long> p;
for (long long i=1;i<=N;i++){ 
    if (N%i==0){ 
        p.push_back(i);
    }
}
long long pro=1;
long long k=p.size();
for (long long i = 0; i < k; i++)
{
    pro *= p[i];
}
return pro;

}
vector Solution::solve(vector &A, vector &B) {
long long n=A.size();
long long m=B.size();
vector ret;
vector G;
for (long long i=0; i <n; i++){
vector temp;
for (long long j=i; j<n; j++){
for (long long k=i; k<=j; k++){
temp.push_back(A[k]);
}
G.push_back(*max_element(temp.begin() , temp.end()));
}
}

for(long long i=0;i<G.size();i++){
long long a=productDivisors(G[i]);
G[i]=a;
}

sort(G.begin(), G.end(), greater());

for(long long i=0;i<m;i++) {
ret.push_back(G[B[i]-1]);
}
return ret;
}