Unable to find my mistake

My code executes while testing but does not pass all test cases while submitting. The image attached has the test case which doesn’t pass.

Please find my code below:

#define ll long long

int divisorProd(int num){
    if(num <= 2)
        return num;
    ll prod = 1;
    for(int i=1; i<=sqrt(num); i++){
        if(num%i==0){
            if(num/i == i)
                prod = prod*(num/i);
            else
                prod = prod*num;
        }
    }
    return prod%(1000000007);
}

bool comp(int x, int y){
    return x>y;
}

vector<int> Solution::solve(vector<int> &a, vector<int> &B) {
    vector<int> x;
    // x[0] = -100;
    // cout<<A[0]<<" "<<x[0];
    // int start = 0, end = 0;
    int max = 0;
    int n = a.size();
    int ele = 0;
    for(int i=0; i<n; i++){
        max = a[i];
        ele = divisorProd(a[i]);
        x.push_back(ele);
        for(int j=i+1; j<n; j++){
            if(max < a[j]){
                max = a[j];
            }
            ele = divisorProd(max);
            x.push_back(ele);
        }
    }
    sort(x.begin(),x.end(),comp);
    vector<int> y;
    // vector<int>::iterator iter;
    for(int i=0; i<B.size(); i++){
        y.push_back(x[B[i] - 1]);
    } 
    return y;
}

I’m stuck in the exact same case with the exact same output. My solution is in java

Try adding modulo while calculating the product. For instance,
prod = prod*num%1000000007;

Check your divisors product calculation. Here is my code:

            # product of divisors of `x`:
            d = 2
            res = x
            while d * d <= x:
                if x % d == 0:
                    res = (res * d) % MOD
                    if d * d != x:
                        res = (res * (x // d)) % MOD
                d += 1
            #  res - result
Click here to start solving coding interview questions