Skip to content

Commit 2477882

Browse files
authored
Create 2438_range_product_queries_of_powers.rs
1 parent b3afdb1 commit 2477882

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
impl Solution {
2+
pub fn product_queries(n: i32, queries: Vec<Vec<i32>>) -> Vec<i32> {
3+
const MODULO: i64 = 1_000_000_007;
4+
let mut powers = vec![];
5+
for i in 0..32 {
6+
if 1 & (n >> i) == 1 {
7+
powers.push(2_i32.pow(i as u32));
8+
}
9+
}
10+
queries.iter().map(|q| {
11+
let mut product = 1i64;
12+
for i in q[0] as usize..=q[1] as usize {
13+
product = (product * powers[i] as i64) % MODULO;
14+
}
15+
product as i32
16+
}).collect()
17+
}
18+
}

0 commit comments

Comments
 (0)