-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMGCSET.java
More file actions
65 lines (41 loc) · 1.08 KB
/
MGCSET.java
File metadata and controls
65 lines (41 loc) · 1.08 KB
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
55
56
57
58
59
60
61
62
63
64
65
// Akash Yadav
// @Hudson Lane, Delhi
// 12th July 18
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
class TestClass{
//https://www.codechef.com/JULY18B/problems/MGCSET
public static Scanner scn = new Scanner(System.in);
public static void main (String[] args) throws java.lang.Exception{
int T = scn.nextInt();
while(T-- > 0){
int N = scn.nextInt();
int M = scn.nextInt();
ArrayList<Integer> arr = new ArrayList<>();
for(int i = 0; i < N; i++)
arr.add(scn.nextInt());
//count the number of terms divisible by M
int count = 0;
for(int i = 0; i < N; i++){
int num = arr.get(i);
if(num % M == 0)
count++;
}
//answer is all possible combinations of count
// answer = 2^count - 1
long answer = power(2, count) - 1;
System.out.println(answer);
}
}
public static long power(int base, int power){
if(power == 0) return 1;
if(power == 1) return base;
long answer = power(base, power/2);
answer = answer * answer;
if(power % 2 != 0)
answer *= base;
return answer;
}
}