-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathP117.java
55 lines (43 loc) · 1.17 KB
/
P117.java
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
/*
117. Counting
time limit per test: 0.25 sec.
memory limit per test: 4096 KB
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
4 2 50
9 10 11 12
Sample Output
1
*
*/
import java.util.*;
public class P117 {
public static int powMod(int n, int m, int k) {
if(m == 1)
return n % k;
int res = powMod(n, m / 2, k);
res = res * res % k;
if(m % 2 != 0)
res = res * n % k;
return res;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int k = in.nextInt();
int cnt = 0;
for(int i = 0; i < n; i++) {
if(powMod(in.nextInt(), m, k) == 0)
cnt++;
}
System.out.print(cnt);
}
}