Tap here to switch tabs
Problem
Submissions

Problem: Count Connected Components in LCM Graph

med
30 min
Try to solve the Count Connected Components in LCM Graph problem.

Statement

You are given an array of unique positive integers nums and a positive integer threshold.

Consider an undirected graph where each element of nums represents a node. There is an edge between two distinct nodes nums[i] and nums[j] if and only if $ ext{lcm}(nums[i], nums[j]) \le$ threshold, where $ ext{lcm}(x, y)$ denotes the least common multiple of xx and yy.

Return the total number of connected components in this graph.

Constraints:

  • 1≤1 \le nums.length ≤105\le 10^5

  • 1≤1 \le nums[i] ≤109\le 10^9

  • All elements of nums are unique.

  • 1≤1 \le threshold ≤2imes105\le 2 imes 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Connected Components in LCM Graph

med
30 min
Try to solve the Count Connected Components in LCM Graph problem.

Statement

You are given an array of unique positive integers nums and a positive integer threshold.

Consider an undirected graph where each element of nums represents a node. There is an edge between two distinct nodes nums[i] and nums[j] if and only if $ ext{lcm}(nums[i], nums[j]) \le$ threshold, where $ ext{lcm}(x, y)$ denotes the least common multiple of xx and yy.

Return the total number of connected components in this graph.

Constraints:

  • 1≤1 \le nums.length ≤105\le 10^5

  • 1≤1 \le nums[i] ≤109\le 10^9

  • All elements of nums are unique.

  • 1≤1 \le threshold ≤2imes105\le 2 imes 10^5