Count Multiples of K
EasyPractice library · +10 XPdynamic programmingiterationnumber theory
Given a list of N integers and an integer K, count how many integers in the list are divisible by K. An integer 'a' is divisible by K if 'a' modulo K is equal to 0.
Input
The first line contains two integers N and K, separated by a space. The second line contains N integers, a_1, a_2, ..., a_N, separated by spaces.
Output
Print a single integer: the count of numbers in the list that are divisible by K.
Constraints
1 <= N <= 1000; 1 <= K <= 1000; -1000 <= a_i <= 1000
Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests
Example 1
Input
5 3 1 2 3 4 5
Output
1
Only the number 3 is divisible by 3.
Example 2
Input
6 2 2 4 6 8 10 12
Output
6
All 6 numbers are divisible by 2.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
5 3 1 2 3 4 5
Example 2 input
6 2 2 4 6 8 10 12