You are working at a factory that produces electronic components. Each component is assigned a unique serial number. As part of a new quality control initiative, a component is flagged for inspection if its serial number is evenly divisible by a specific integer K.
You are given a batch of N components, represented by an array A of their serial numbers, and a single integer K. Your task is to count how many components in this batch need to be flagged for inspection.
The first line of input contains two space-separated integers, N (the number of components) and K (the divisor).
The second line contains N space-separated integers, the elements of the array A (the serial numbers).
The output should be a single integer representing the total count of elements in A that are evenly divisible by K.
An integer a is evenly divisible by an integer b if the remainder of their division is 0. In most programming languages, this is checked with the modulo operator: a % b == 0.
The value of K will always be a positive integer.
5 3
1 2 3 4 6
2
We need to check which of the numbers [1, 2, 3, 4, 6] are divisible by 3.
- 1 % 3 != 0
- 2 % 3 != 0
- 3 % 3 == 0 (Count: 1)
- 4 % 3 != 0
- 6 % 3 == 0 (Count: 2)
The total count is 2.
4 1
10 20 30 40
4
Every integer is evenly divisible by 1. Therefore, all 4 elements are counted.
The expected time complexity is O(N), where N is the number of elements in the array.
1 <= N <= 10^5
1 <= K <= 10^9
1 <= A[i] <= 10^9
Time limit: 1 sec