Just a runnable solution
\n\nimpl Solution {\n    pub fn find_products_of_elements(queries: Vec<Vec<i64>>) -> Vec<i32> {\n        let mx = 1_000_000_000_000_006;\n        let lim = 60;\
\n```\nimpl Solution {\n    pub fn find_products_of_elements(queries: Vec<Vec<i64>>) -> Vec<i32> {\n        let mx = 1_000_000_000_000_006;\n        let lim = 60;\n        let mut ret = vec![];\n\n        let mul = |x: i64, y: i64, m: i64| -> i64 {\n            let x = x % m;\n            let y = y % m;\n            let res = x * y;\n            if res >= m {\n                res % m\n            } else {\n                res\n            }\n        };\n\n        let mod_pow = |x: i64, y: i64, m: i64| -> i64 {\n            if y <= 0 {\n                return 1;\n            }\n            let mut ans = 1;\n            let mut x = x % m;\n            let mut y = y;\n            while y != 0 {\n                if y & 1 == 1 {\n                    ans = mul(ans, x, m);\n                }\n                x = mul(x, x, m);\n                y >>= 1;\n            }\n            ans\n        };\n\n        let calc = |n: i64| -> i64 {\n            if n <= 0 {\n                return n;\n            }\n            let mut lo = 1;\n            let mut hi = mx;\n            while lo <= hi {\n                let mid = (lo + hi) / 2;\n                let mut sum = 0;\n                for i in 0..lim {\n                    let p = 1_i64 << (i + 1);\n                    let mut cur = ((mid + 1) / p) * (1_i64 << i);\n                    cur += 0_i64.max((mid + 1) % p - (1_i64 << i));\n                    sum += cur;\n                }\n                if sum >= n {\n                    hi = mid - 1;\n                } else {\n                    lo = mid + 1;\n                }\n            }\n            hi + 1\n        };\n\n        let calc2 = |n: i64, tot: i64| -> Vec<i64> {\n            let mut cnt = vec![0; lim];\n            if n <= 0 {\n                return cnt;\n            }\n            let mut sum = 0;\n            for (i, cnt_i) in cnt.iter_mut().enumerate().take(lim) {\n                let p = 1_i64 << (i + 1);\n                let mut cur = (n / p) * (1_i64 << i);\n                cur += 0_i64.max(n % p - (1_i64 << i));\n                sum += cur;\n                *cnt_i = cur;\n            }\n            if sum < tot {\n                for (i, cnt_i) in cnt.iter_mut().enumerate().take(lim) {\n                    if sum >= tot {\n                        break;\n                    }\n                    if (n >> i) & 1 == 1 {\n                        *cnt_i += 1;\n                        sum += 1;\n                    }\n                }\n            }\n            cnt\n        };\n\n        for q in queries {\n            let v1 = calc2(calc(q[1] + 1), q[1] + 1);\n            let v2 = calc2(calc(q[0]), q[0]);\n\n            let mut val = 1;\n            for i in 0..lim {\n                let p = 1_i64 << i;\n                let temp = mod_pow(p, v1[i] - v2[i], q[2]);\n                val = (val * temp) % q[2];\n            }\n            ret.push(val as i32);\n        }\n        ret\n    }\n}\n\n```
['Rust']