1. GoodArray For a number N, a goodArray is the smallest possible array that consists of only powers of two (20, 2¹ ...
Posted: Fri Jul 08, 2022 6:15 am
1. GoodArray For a number N, a goodArray is the smallest possible array that consists of only powers of two (20, 2¹ ... 2k) such that the sum of all the numbers in the array is equal to N. For each query that consists of three integers /, r, and m, find out the product of elements goodArray[1] through goodArray[r] modulo m when goodArray is sorted in non- decreasing order. Example For N = 26, queries = [[1, 2, 1009], [3, 3, 5]] goodArray when sorted is [2,8,16]. For query /= 1, r = 2, m= 1009, ans = goodArray[1] * goodArray[2] = (2*8) modulo 1009 = 16. For query /= 3, r = 3, m=5, ans = goodArray3 = (16) modulo 5 = 1. The answer is [16, 1]. Function Description Complete the function getQueryResults in the editor below. getQueryResults has the following parameters: long N: the integer N int queries[q][3]: a 2D array of queries, each with 3 elements I, r, and m. Return int answer[q]: the answers to the queries