Sgu-117-counting (Quick power modulo!) )

Source: Internet
Author: User
Tags integer numbers

SGU-117

Counting
Time Limit: 250MS Memory Limit: 4096KB 64bit IO Format: %i64d &%i64u

Submit Status

Description

Find amount of numbers for given sequence of integers numbers such that after raising them to the M-th Power they Would be divided by K.

Input

Input consists of lines. There is three integer numbers N, M, K (0<n, M, k<10001) on the first line. There is N positive integer numbers? Given sequence (each number isn't more than 10001)? On the second line.

Output

Write answer for given task.

Sample Input

4 2 509 10 11 12

Sample Output

1
Author : Michael R. Mirzayanov
Resource : Phtl #1 Training Contests
Date : Fall 2001

Source




Test instructions: The first line gives n,m,k three integers, the second line gives n integers, judging whether the second of these integers can be divisible by K, simple and fast power can be.


AC Code:


#include <cstdio> #include <cstring> #include <algorithm>  using namespace std;  int Q_pow (int n, int m, int k)  {      int result=1;      while (m)  //fast power     {          if (m&1)     //Determines whether it is an odd         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 ans = 0;          for (int i=0; i<n; i++)          {          int A;            scanf ("%d", &a);              if (Q_pow (A, M, K) ==0)  ans++;          }          printf ("%d\n", ans);      }      return 0;  }


Sgu-117-counting (Quick power modulo!) )

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.