• + 0 comments

    hey if anyone is looking here a very basic c++ code in this code I used loops to first get all the elements in array that divide all the values between max of a and min of b

    then I stored those a[]'s in new array that I again run a for loop to found count if all elelments in new array divide elements of array b

    here is the code ` //code written on date:17 aug 2018 hacker rank between two sets problem

    include

    using namespace std;

    int getTotalX(int a [], int b [],int n ,int m) { int a_max=a[0],b_min=b[0];

    for(int i=0; i<n; i++)
    { 
    
        if(a[i]>a_max)
        a_max=a[i];
    }
    
    for(int j=0; j<m; j++)
    { 
    
        if(b[j]<b_min)
        b_min=b[j];
    }
    

    // cout<=a_max){

    for(int k=b_min; k>=a_max; k--)
    {
        int cnt=0;
        for(int i=0; i<n; i++ )
        {
            if(k%a[i]==0)
            {
                cnt++;
    
            }   
            //cout<<"count is "<<cnt<<endl;
        }       
        if(cnt==n) 
            {
                newarr[p]=k; 
                //cout<<"arr[]:  "<<newarr[p]<<","<<endl;
                p++;
            }
    
    
    }
    

    } /----------------------------------------------------------------------------/ //cout<<"p:"<

    int finalcount=0; for(int i=0; i

    for (int j=0; j<m; j++)
    {
    
    if(b[j]%newarr[i]==0) cnt1++;   
    
    }
    
    if(cnt1==m) finalcount++;
    

    }

    //cout<<"finalcount"<

    return finalcount;
    

    }

    int main() { int n,m; cin>>n>>m; int a[n],b[m]; for(int i=0; i

        cin>>a[i];
    }
    for(int j=0; j<m; j++)
    {
    
        cin>>b[j];
    }
    

    cout<

    return 0;   
    

    }`