Imagine you have an array of integers, and you want to determine if you can create a connected network where any two positions can reach each other through a series of jumps.
You are given a 0-indexed integer array nums. You can traverse (or jump) between index i and index j if and only if gcd(nums[i], nums[j]) > 1, where gcd is the greatest common divisor.
Your task is to determine if every pair of indices in the array can be connected through a sequence of valid traversals. In other words, can you reach any index from any other index by following the GCD rule?
Example: If nums = [2, 3, 6], you can traverse between indices 0 and 2 (since gcd(2,6)=2 > 1), and between indices 1 and 2 (since gcd(3,6)=3 > 1). This means all indices are connected through index 2.
Return true if it's possible to traverse between all pairs of indices, or false otherwise.
Input & Output
Constraints
- 1 โค nums.length โค 105
- 1 โค nums[i] โค 105
- All values in nums are positive integers
- Arrays with length 1 should return true