• + 0 comments

    // Get the last element of set 'a' and the first element of set 'b' int startRange = a.get(a.size() - 1); Click Here int endRange = b.get(0);

    // You can now iterate over the range from startRange to endRange for (int i = startRange; i <= endRange; i++) { // Check if 'i' is divisible by all elements of 'a' and is a factor of all elements of 'b' boolean divisibleByAllA = true; boolean factorOfAllB = true;

    for (int num : a) {
        if (i % num != 0) {
            divisibleByAllA = false;
            break;
        }
    }
    
    for (int num : b) {
        if (num % i != 0) {
            factorOfAllB = false;
            break;
        }
    }
    
    if (divisibleByAllA && factorOfAllB) {
        // Your logic for valid integer within range
        System.out.println(i);
    }
    

    }