Count Numbers Divisible by K
EasyPractice library · +10 XPdynamic programmingarraysbasic programming
Given a list of N integers, find out how many of them are perfectly divisible by a given integer K. Print this count.
Input
The first line contains two integers N and K. The second line contains N integers separated by spaces.
Output
Print a single integer: the count of numbers divisible by K.
Constraints
1 <= N <= 1000 1 <= K <= 1000 Each integer in the list is between -1000 and 1000.
Time limit 1 s (native code; slower languages get more)Memory 256 MB15 hidden tests
Example 1
Input
5 3 1 2 3 4 5
Output
1
Only 3 is divisible by 3, so the count is 1.
Example 2
Input
6 2 10 20 30 40 50 60
Output
6
All 6 numbers are divisible by 2, so the count is 6.
Hints
Similar problems
- Count Consecutive OccurrencesEasy
- Maximum Sum of Non-Adjacent ElementsHard
- Print Sum of DigitsEasy
- Sum of First K MultiplesEasy
- Find Second Largest ElementEasy
- Maximum Sum of Non-Adjacent Elements in a Circular ArrayMedium
More topics: Arrays problems, Dynamic Programming problems, Beginner Coding Problems problems
# 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 10 20 30 40 50 60