#C14398. Sum of Primes in a Range
Sum of Primes in a Range
Sum of Primes in a Range
Given two integers a
and b
, your task is to compute the sum of all prime numbers between a
and b
(inclusive). A prime number is an integer greater than 1 that has no positive divisors other than 1 and itself.
Note that even if the input range includes negative numbers, prime numbers are defined only for integers greater than 1. The mathematical formulation of the problem is given by: $$S = \sum_{p \in P \cap [a, b]} p$$, where \(P\) represents the set of all prime numbers.
Make sure your solution reads the input from stdin and writes the result to stdout.
inputFormat
The input consists of two space-separated integers, a
and b
, representing the range in which to sum the prime numbers. The integers may be provided in any order; if a > b
, consider the range from b
to a
.
outputFormat
Output a single integer representing the sum of all prime numbers in the inclusive range from a
to b
. If there are no prime numbers in the range, output 0.## sample
10 20
60