As reported: Rubrik SDE-1 online assessment (2025) — the hard question of the test, titled "GCD Subsequence".
You are given an array A of N positive integers and a list of independent queries. Each query is a pair (k, g):
k— the desired subsequence size,g— the target GCD.
For each query, decide whether there exists a subsequence of exactly k elements whose GCD equals g. Answer "YES" or "NO".
Example 1
A = [6,10,15,4], queries = [[2,2],[3,1],[2,5],[1,7],[4,1]]
-> ["YES","YES","YES","NO","YES"]
gcd(6,10) = 2; gcd(6,10,15) = 1; gcd(10,15) = 5; no element equals 7; gcd(6,10,15,4) = 1.
Example 2
A = [2,4,8], queries = [[1,2],[2,2],[3,2],[2,4]]
-> ["YES","YES","YES","YES"]
Constraints: 1 ≤ N ≤ 10^5; 1 ≤ A[i] ≤ 10^5; 1 ≤ k ≤ 5; 1 ≤ g ≤ 10^5; up to 10^5 queries.
Code runner format: two lines — A as a JSON array, and the queries as a JSON array of [k, g] pairs. Implement answerQueries(nums, queries); the harness prints the list of answers.