cswork / OA打开练习工作台

QuoraOA #1

Count Powers of K (MLE)

简单可在线判题

考点(AI 标注)位运算

Given an integer array arr and an integer k, count how many numbers in the array are powers of k, that is, numbers that can be written as k^e for a positive integer e.

输入格式

The first line contains two integers n and k; the second line contains n integers arr[0..n−1]. 1≤n≤200000, 2≤k≤10^18, 2≤arr[i]≤10^18.

输出格式

Output one integer: the number of elements that are powers of k.

样例 1

输入:

3 11
11 121 10

输出:

2

样例 2

输入:

5 2
2 4 6 8 1024

输出:

4

样例 3

输入:

3 5
10 20 30

输出:

0

样例说明

Example 1: arr=[11,121,10], k=11. 11=11^1 and 121=11^2, but 10 is not, so the answer is 2. Example 2: 2, 4, 8, and 1024 are all powers of 2, but 6 is not, so the answer is 4. Example 3: none of 10, 20, 30 is a power of 5, so the answer is 0.