SGU117—Counting (快速幂取模)

来源:互联网 发布:淘宝色差问题怎么回复 编辑:程序博客网 时间:2024/06/14 09:04

117. Counting

time limit per test: 0.5 sec.
memory limit per test: 4096 KB

Find amount of numbers for given sequence of integer numbers such that after raising them to theM-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 than10001) − on the second line.

Output

Write answer for given task.

Sample Input

4 2 509 10 11 12

Sample Output

1

 

 

题目是说,样例的第一行为三个数n,m,k;然后第二行有n个数,求第二行中,每个数的m次方能被k整除的个数。——快速幂

 

 

//题目大意:给定n个数,问这n个数的m次幂有多少能够被K整除。#include<iostream>#include<string.h>#include<stdio.h>#include<ctype.h>#include<algorithm>#include<stack>#include<queue>#include<set>#include<math.h>#include<vector>#include<map>#include<deque>#include<list>using namespace std;int a[99999];int quick_pow(int n,int m,int k){    int result=1;    while(m)    {        if(m&1)        result=(result*n)%k;        n=n*n%k;        m>>=1;    }    return result%k;}int main(){    int n,m,k;    while(scanf("%d%d%d",&n,&m,&k)!=EOF)    {        int count=0;        for(int i=0;i<n;i++)        {            scanf("%d",&a[i]);            if(quick_pow(a[i],m,k)==0)            count++;        }        printf("%d\n",count);    }    return 0;}


 


原创粉丝点击