You are given an integer array
nums
of lengthn
and an integer arrayqueries
.Let
gcdPairs
denote an array obtained by calculating the GCD of all possible pairs(nums[i], nums[j])
, where0 <= i < j < n
, and then sorting these values in ascending order.For each query
queries[i]
, you need to find the element at indexqueries[i]
ingcdPairs
.Return an integer array
answer
, whereanswer[i]
is the value atgcdPairs[queries[i]]
for each query.The term
gcd(a, b)
denotes the greatest common divisor ofa
andb
.
3311. Construct 2D Grid Matching Graph Layout
You are given a 2D integer array
edges
representing an undirected graph havingn
nodes, whereedges[i] = [ui, vi]
denotes an edge between nodesui
andvi
.Construct a 2D grid that satisfies these conditions:
- The grid contains all nodes from
0
ton - 1
in its cells, with each node appearing exactly once.- Two nodes should be in adjacent grid cells (horizontally or vertically) if and only if there is an edge between them in
edges
.It is guaranteed that
edges
can form a 2D grid that satisfies the conditions.Return a 2D integer array satisfying the conditions above. If there are multiple solutions, return any of them.