Counting

Problem Description

Find amount of numbers for given sequence of integer numbers such that after raising them to the M-th power they will be divided by K.

Input

Input consists of two lines. There are three integer numbers N, M, K (0<N, M, K<10001) on the first line. There are N positive integer numbers − given sequence (each number is not more than 10001) − on the second line.

Output

Write answer for given task.

Sample Input

1
2
4 2 50
9 10 11 12

Sample Output

1
1

Solution

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
#include <bits/stdc++.h>

int main() {
std::ios::sync_with_stdio(false);

auto factors = [](int x) -> std::map<int, int> {
std::map<int, int> res{};
for(int i = 2; i * i <= x; i++) {
if(x % i == 0) {
int cnt = 0;
while(x % i == 0) {
x /= i;
cnt += 1;
}
res[i] = cnt;
}
}
if(x != 1) {
res[x] = 1;
}
return res;
};

int n, m, k;
std::cin >> n >> m >> k;
auto k_factors = factors(k);

int count = 0;
while(n--) {
int num;
std::cin >> num;
auto num_factors = factors(num);
bool is_divided = true;
for(const auto& k_factor : k_factors) {
auto it = num_factors.find(k_factor.first);
if(it == num_factors.end() || it->second * m < k_factor.second) {
is_divided = false;
break;
}
}
count += is_divided;
}

std::cout << count << std::endl;
return 0;
}