#C4643. Sum Divisible by D

    ID: 48204 Type: Default 1000ms 256MiB

Sum Divisible by D

Sum Divisible by D

Given an array of integers and an integer \(d\), your task is to compute the sum of all the elements in the array that are divisible by \(d\). If no such element exists, the answer should be \(0\).

Input Format: The input is given via standard input. The first line contains two integers \(n\) and \(d\), where \(n\) is the number of elements in the array and \(d\) is the divisor. The second line contains \(n\) space-separated integers.

Output Format: Output a single integer, which is the sum of all numbers in the array that are divisible by \(d\).

Example:

Input:
5 3
1 2 3 4 6

Output: 9

</p>

Constraints:

  • \(1 \leq n \leq 10^5\)
  • \(1 \leq d \leq 10^9\)
  • Each element of the array is an integer that can be positive, zero, or negative.

inputFormat

The input is read from standard input and is formatted as follows:

  1. The first line contains two integers \(n\) and \(d\) separated by a space, where \(n\) denotes the number of elements in the array.
  2. The second line contains \(n\) space-separated integers representing the elements of the array.

Example:

5 3
1 2 3 4 6

outputFormat

Output a single integer to standard output, which is the sum of all integers in the array that are divisible by \(d\). If there are no such integers, output \(0\).

Example:

9
## sample
5 3
1 2 3 4 6
9

</p>