SGU 117Counting(快速幂)

来源:互联网 发布:快速买火车票软件 编辑:程序博客网 时间:2024/06/06 07:08

快速幂水题。

/*********************** author:crazy_石头* Pro:SGU 117* algorithm:quick pow* Time:0ms* Judge Status:Accepted***********************/#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>using namespace std;#define LL long long#define rep(i,h,n) for(int i=(h);i<=(n);i++)#define ms(a,b) memset((a),(b),sizeof(a))#define INF 1<<29const int maxn=10000+5;int n,m,k;inline int quick_pow(int a,int b){    int ret=1;    while(b)    {        if(b&1)        ret=(LL)ret*a%k;        b>>=1;        a=(LL)a*a%k;    }    return ret;}int main(){    scanf("%d%d%d",&n,&m,&k);    int cnt=0,s,h;    rep(i,0,n-1)    {        scanf("%d",&s);        if(quick_pow(s,m)%k==0)        cnt++;    }    printf("%d\n",cnt);    return 0;}


 

原创粉丝点击