Imagine you're a city planner working on a transportation network for n cities numbered from 1 to n. The unique rule for building roads is fascinating: two cities can be directly connected if they share a common divisor greater than a given threshold.
More specifically, cities x and y have a bidirectional road between them if there exists an integer z such that:
x % z == 0(z divides x)y % z == 0(z divides y)z > threshold
Your task is to answer multiple queries asking whether two cities are connected (directly or through a path of roads). Given n, threshold, and an array of queries where each query is [a, b], return an array of boolean values indicating connectivity.
Goal: Efficiently determine if cities can reach each other through the road network.
Input: Number of cities n, threshold value, and queries array
Output: Boolean array indicating connectivity for each query
Input & Output
Constraints
- 1 โค n โค 104
- 0 โค threshold โค n
- 1 โค queries.length โค 105
- queries[i].length == 2
- 1 โค ai, bi โค n
- ai != bi