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!) )