-
Notifications
You must be signed in to change notification settings - Fork 0
/
Issue 111
54 lines (47 loc) · 1.04 KB
/
Issue 111
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Issue111 {
public int[] productQueries(int n, int[][] q) {
int x=getPow(n);
int f=1;
int[] p=new int[x];
p[0]=1;
for(int i=1;i<x;i++){
f=f*2;
p[i]=f;
}
int k=x-1;
int m=0;
while(k>=0){
if(n>=p[k]){
n=n-p[k];
m++;
}else{
p[k]=0;
}
k--;
}
int[] s=new int[m];
int d=0;
for(int i=0;i<x;i++){
if(p[i]>0){
s[d++]=p[i];
}
}
int[] r=new int[q.length];
int z=1000000007;
for(int i=0;i<r.length;i++){
int g = 1;
for(int j=q[i][0];j<=q[i][1];j++){
//typecasting it into integer
g=(int)((long)g*s[j]%z);
}
r[i]=g;
}
return r;
}
int getPow(int n){
if(n==0){
return 0;
}
return 1+getPow(n/2);
}
}