JS Solution - Binary search
Pro tip: Big heart for lil Xie \uD83D\uDC9C\uD83D\uDC9C\uD83D\uDC9C\n\n# Complexity\n- let n = queries.length, m = max(queries[*][1])\n- Time complexity: O(nlog
Pro tip: Big heart for lil Xie \uD83D\uDC9C\uD83D\uDC9C\uD83D\uDC9C\n\n# Complexity\n- let `n = queries.length`, `m = max(queries[*][1])`\n- Time complexity: $$O(nlogm)$$\n- Space complexity: $$O(n + m)$$\n\n# Code\n```js\nfunction quickPow(a, b, m) {\n  if (b === 0) return 1;\n  let t = quickPow(a, Math.floor(b / 2), m);\n  t = (t * t) % m;\n  if (b % 2) t = (t * a) % m;\n  return t;\n}\n\nconst pcL = Array(50).fill(0);\nconst pcR = Array(50).fill(0);\nconst temps = Array(50).fill(0);\n\n/**\n * @param {number} maxCnt\n * @param {number[]} pows\n */\nfunction cntPows(maxCnt, pows) {\n  let resNum = 0;\n  let resCnt = 0;\n\n  let l = 0;\n  let r = 1e15;\n\n  while (l <= r) {\n    temps.fill(0);\n    let m = Math.floor((l + r) / 2);\n    let p = 1;\n    let c = 0;\n    let t = m;\n\n    for (let i = 0; t; i++, p *= 2) {\n      let cb = 0;\n      if (t % 2) {\n        cb = (m % p) + 1;\n      }\n\n      t = Math.floor(t / 2);\n      cb += t * p;\n\n      c += cb;\n      if (c > maxCnt) break;\n      temps[i] = cb;\n    }\n\n    if (c > maxCnt) {\n      r = m - 1;\n    } else {\n      l = m + 1;\n      resNum = m;\n      resCnt = c;\n      for (let i = 0; i < 50; ++i) {\n        pows[i] = temps[i];\n      }\n    }\n  }\n\n  ++resNum;\n  for (let i = 0; resCnt < maxCnt; ++i) {\n    if (resNum % 2) {\n      ++pows[i];\n      ++resCnt;\n    }\n    resNum = Math.floor(resNum / 2);\n  }\n}\n\n/**\n * @param {number[][]} queries\n * @return {number[]}\n */\nvar findProductsOfElements = function (queries) {\n  let n = queries.length;\n  let res = new Uint32Array(n);\n\n  for (let i = 0; i < n; ++i) {\n    let [l, r, m] = queries[i];\n    ++r;\n    cntPows(l, pcL);\n    cntPows(r, pcR);\n    let cur = 1;\n    let p = 1;\n\n    for (let j = 0; j < 50; ++j, p = (p * 2) % m) {\n      cur = (cur * quickPow(p, pcR[j] - pcL[j], m)) % m;\n    }\n    res[i] = cur;\n  }\n\n  return res;\n};\n```
['Binary Search', 'JavaScript']