• + 0 comments

    **Java Solution **

    public static int getTotalX(List<Integer> a, List<Integer> b) {
    
        /* Assuming the last value in 'a' is the maximum and
           the first value in 'b' is the minimum */
    
        int start = a.get(a.size()-1),end=b.get(0),count=0;
    
                for (int i = start; i <= end; i+=start) { 
    
                    boolean trueForA = true, trueForB = true ;
    
                    for (int num : a) {
                        if (i % num != 0) {
                            trueForA = false;
                            break;
                        }
                    }
    
                    for (int num : b) {
                        if(trueForA)
                            if (num % i != 0) {
                            trueForB = false;
                            break;
                        }
                      }
    
    
                    if (trueForA &&  trueForB) {
                       count++;
                     }
             }
        return count;
    }