#C11303. Prime Product Queries
Prime Product Queries
Prime Product Queries
You are given T test cases. Each test case contains two integers l and r representing an inclusive range. Your task is to compute the product of all prime numbers within the range [l, r] modulo \(10^9+7\). If there are no prime numbers in the range, output -1
.
To solve this problem efficiently, you should precompute all prime numbers up to \(10^6\) using the Sieve of Eratosthenes. Then, process each query by iterating over the primes that lie in the given range and multiplying them under modular arithmetic.
Note: If there is no prime in the specified range, the output should be -1
.
inputFormat
The first line contains an integer T
denoting the number of test cases. Each of the following T
lines contains two space-separated integers l
and r
describing the range.
Input Format:
T
l1 r1
l2 r2
...
lT rT
outputFormat
For each test case, print the product of all primes in the inclusive range [l, r]
modulo \(10^9+7\) on a new line. If there are no primes, output -1
.
3
1 10
10 20
20 30
210
46189
667
</p>