3378. Count Connected Components in LCM Graph
You are given an array of integers
nums
of sizen
and a positive integerthreshold
.There is a graph consisting of
n
nodes with theith
node having a value ofnums[i]
. Two nodesi
andj
in the graph are connected via an undirected edge iflcm(nums[i], nums[j]) <= threshold
.Return the number of connected components in this graph.
A connected component is a subgraph of a graph in which there exists a path between any two vertices, and no vertex of the subgraph shares an edge with a vertex outside of the subgraph.
The term
lcm(a, b)
denotes the least common multiple ofa
andb
.
1 | class Solution { |