SGU 117 Counting(快速幂|二分)

 

//SGU 117 Counting
//二分
//by night_watcher

#include<iostream>
#include<cstring>
using namespace std;

#define ll long long

ll m,k;

ll pow(int a,int b){
    if(b==1) return a%k;
    if(b%2==0){
        ll tmp=pow(a,b/2);
        return (tmp*tmp)%k;
    }
    ll tmp=pow(a,b/2);
    return tmp*tmp%k*a%k;
}

int main(){
    int n,i,j,ans;
    cin>>n>>m>>k;
    ans=0;
    for(i=0;i<n;i++){
        cin>>j;
        if(pow(j,m)%k==0) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


 

你可能感兴趣的:(SGU 117 Counting(快速幂|二分))