#C10089. Prime Ranges Query

    ID: 39255 Type: Default 1000ms 256MiB

Prime Ranges Query

Prime Ranges Query

You are given Q queries. For each query, you are given two integers a and b. Your task is to find all prime numbers in the range \([a,b]\) (inclusive). A number \(p\) is called prime if \(p > 1\) and it has no positive divisors other than 1 and itself, i.e. $$p > 1 \quad\text{and}\quad \forall d \in \mathbb{N},\,1 < d < p \Rightarrow d \nmid p.$$ If there are no prime numbers in the given range, output -1.

inputFormat

The first line of input contains a single integer Q, the number of queries. Each of the next Q lines contains two space-separated integers a and b representing the endpoints of the range. Note that the two numbers may not be in ascending order.

outputFormat

For each query, output a single line containing all the prime numbers in the inclusive range [a, b] in ascending order, separated by a single space. If the range contains no prime numbers, output -1.## sample

2
4 10
20 30
5 7

23 29

</p>