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
#include <bits/stdc++.h>
using namespace std;
int n,m,k;
int qpow(int x, int y){
int now=1;
while(y>0){
if(y&1){
now=(x*now)%k;
}
y>>=1;
x=(x*x)%k;
if(now==0)return 0;
}
return now;
}
void solve(){
scanf("%d%d%d",&n,&m,&k);
int ans=0;
while(n--){
int a;
scanf("%d",&a);
if(qpow(a,m)==0){
ans++;
}
}
printf("%d",ans);
}
int main(){
solve();
return 0;
}