Problem: Count of distinct coprime pairs product of which divides all elements in index [L, R] for Q queries
Given an array arr[] of N integers and Q queries of the form (l, r). The task is to find the number of distinct pairs of coprime integers for each query such that all integers in index range [l, r] are divisible by the product of the coprime integers.

Sample Input: arr[] = {1, 2, 2, 4, 5}, queries[] = {{2, 3}, {2, 4}, {3, 4}, {4, 4}, {4, 5}}
Sample Output: 3 3 3 5 1
Explanation: For 1st query [2, 3], the subarray is {2, 2}.
The pairs of coprimes that divide all the integers in the subarray are {1, 1}, {1, 2} and {2, 1}.
For 2nd query [2, 4], the subarray is {2, 2, 4}.
The pairs of coprimes that divide all the integers are {1, 1}, {1, 2} and {2, 1}.
Similarly, proceed for the further queries.

Solution (python):
# python program for the above approach
import math
MAXN = 200001

# creating 2-D table of size 1001*1001
table = []

for i in range(0, 1001):
    table.append([])
    for j in range(0, 1001):
        table[i].append([])

# Function to build sparse table
def buildSparseTable(arr, n):

        # GCD of single element is
        # the element itself
    for i in range(0, n):
        table[i][0] = arr[i]

    # Build sparse table
    for j in range(1, (int)(math.log2(n))+1):
        for i in range(0, n-(1 << j) + 1):
            table[i][j] = math.gcd(
                table[i][j - 1], table[i + (1 << (j - 1))][j - 1])

# Function to return the GCD of
# all elements in range [L, R]
def find_gcd(L, R):
  
    # Highest power of 2 that is not
    # more than count of elements
    j = (int)(math.log2(R - L + 1))

    # Return GCD in range
    return math.gcd(table[L][j],
                    table[R - (1 << j) + 1][j])

# Smallest prime factors array
spf = [0]*MAXN

# Function to build the smallest
# prime factor array using Sieve
def build_spf():

    spf[1] = 1
    for i in range(2, MAXN):
        spf[i] = i
    for i in range(2, MAXN, 2):
        spf[i] = 2

    for i in range(3, (int)(math.sqrt(MAXN))):
        if (spf[i] == i):
            for j in range(i*i, MAXN, i):
                if (spf[j] == j):
                    spf[j] = i

# Function to find the count of
# distinct prime factors of x
def getFactorization(x):
  
    # Stores the required count
    ctr = 0

    while (x != 1):
        ctr += 1

        # Stores smallest prime
        # factor of x
        x = (int)(x)
        p = spf[x]

        while (x % p == 0):
            x = x // p

    # Return count
    return ctr

# Function to count of coprime pairs such
# that the product of the pair divides
# all integers of subarray in given range
def solveQueries(a, n, q):
  
    # Loop to iterate over queries
    for i in range(len(q)):
        l = q[i][0]
        r = q[i][1]
        l -= 1
        r -= 1

        # Stores gcd in the range
        gcd = find_gcd(l, r)

        # Stores the required count
        ans = 0

        # Count the pairs of co-primes
        # integers in given format
        for i in range(1, (int)(math.sqrt(gcd)+1)):

            # If i is a factor of gcd
            if (gcd % i == 0):
                ans = ans + (1 << getFactorization(i))
                if (gcd / i != i):
                    ans += (1
                            << getFactorization(gcd / i))

        # Print answer
        print(ans, end=" ")

# Function to perform precomputation
def preProcess(a, n):
    build_spf()
    buildSparseTable(a, n)

# Driver Code
arr = [1, 2, 2, 4, 5]
queries = [[2, 4], [2, 4], [3, 4], [4, 4], [4, 5]]

preProcess(arr, len(arr))
solveQueries(arr, len(arr), queries)