Its working for smaller numbers ...gives the wron o/p for larger one...can anyone help me out?


#1

#define M 1000000007
long long multiplyFactors(long long n)
{
long long prod = 1;
for (int i = 1; i * i <= n; i++)
{
if (n % i == 0)
{
// If factors are equal,
// multiply only once
if (n / i == i)
prod = (prod * i) % M;

        // Otherwise multiply both 
        else { 
            prod = (prod * i) % M; 
            prod = (prod * n / i) % M; 
        } 
    } 
} 
return (int)prod; 

}
vector Solution::solve(vector &a, vector &b) {

int n=size(a);
int q=size(b);
vector <long long> z;
int i,j,g,m;
for(i=0;i<n;i++){
    m=a[i];
    z.push_back(m);
    if(i!=n-1){
        for(j=i+1;j<n;j++){
            z.push_back(max(m,a[j]));    
        }
    }    
}
g=size(z);
for(i=0;i<g;i++){
    z[i]=multiplyFactors(z[i]);
}
sort(z.begin(),z.end(),greater<long long>());
vector<int> x;
for(i=0;i<q;i++){
    x.push_back(z[b[i]-1]);
}
return x;

}