#C8935. Sum of Primes in Ranges

    ID: 52972 Type: Default 1000ms 256MiB

Sum of Primes in Ranges

Sum of Primes in Ranges

Given an integer T and T test cases, each consisting of two integers L and R, your task is to compute the sum of all prime numbers in the range \( [L, R] \) (inclusive). If \( L < 2 \), consider starting from 2 since 1 is not a prime number.

You are required to read the input from standard input (stdin) and write the output to standard output (stdout).

Note: The upper bound for \( R \) is \( 10^6 \). Efficient prime sieving algorithms such as the Sieve of Eratosthenes are recommended to meet performance constraints.

inputFormat

The first line contains an integer T, representing the number of test cases. Each of the following T lines contains two space-separated integers, L and R, representing the bounds of the range. Constraints: \(1 \leq L \leq R \leq 10^6\).

outputFormat

For each test case, output a single line containing the sum of all prime numbers between L and R (inclusive).

## sample
3
10 20
1 10
14 14
60

17 0

</p>