Given a static array nums, answer multiple range queries asking for the greatest common divisor of all values in a subarray. Since gcd is associative and the array does not change, a sparse table can answer each query efficiently after preprocessing.
nums = static integer array, queries = range gcd requests
gcd value for each query, in order
Example 1:
Input:
nums = [24,36,48,18] queries = [[0,2],[1,3]]
Output:
[12,6]
Explanation:
gcd(24,36,48)=12 and gcd(36,48,18)=6.
Example 2:
Input:
nums = [10,15,25] queries = [[0,1],[1,2]]
Output:
[5,5]
Explanation:
Both queried intervals have gcd 5.