#C12293. Sum of Primes in Range

    ID: 41704 Type: Default 1000ms 256MiB

Sum of Primes in Range

Sum of Primes in Range

You are given a list of integers and two additional integers min_value and max_value representing a closed interval \([min_value, max_value]\). Your task is to compute the sum of all the elements in the list that are prime numbers and lie within the given interval.

A prime number is an integer greater than 1 that has no positive divisors other than 1 and itself. The function is_prime(n) returns true if \(n\) is prime and false otherwise. Using this helper, you should sum up only those numbers which are prime and satisfy \(min\_value \le n \le max\_value\).

Note: The input is read from the standard input (stdin) and the output is printed to the standard output (stdout).

inputFormat

The input consists of two lines.

  • The first line contains three integers: n, min_value, and max_value where n is the number of elements in the list.
  • The second line contains n space-separated integers representing the list.

Constraints:

  • \(1 \le n \le 10^5\)
  • The elements of the list and the values \(min_value\) and \(max_value\) are within a reasonable range to avoid overflow.

outputFormat

Output a single integer, which is the sum of all prime numbers in the list that lie within the interval \([min_value, max_value]\).

## sample
5 1 10
1 4 6 8 10
0