# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Limits
1s, 512 MB

A positive integer number n is called a prime number, if it is only divisible by 1 and n itself, where 1 != n. There exists an infinitely many prime numbers! But as the number gets larger, the distribution of primes among them gets less frequent.

You want to investigate the distribution of prime numbers. As a part of this investigation, you want to find out the largest prime number in a given range.

The first line contains an integer **Q** (1 ≤ Q ≤ 10^{5}), the number of queries that will be given. The next Q lines will contain two integers **l _{i}** (1 ≤ l

For each line of query, print a single line, containing the largest prime in the range l_{i} and r_{i} inclusive. If there is no prime numbers in a given range, print -1 instead. Please see the samples for the exact formatting.

Input | Output |
---|---|

5 25 28 1 1 2 3 8 12 14 20 | -1 -1 3 11 19 |

83% Solution Ratio

oneoff.ZQa4IH1LSeEarliest,

ishtupeedFastest, 0.0s

RedwanuzzamanLightest, 3.8 MB

habijabiShortest, 314B

Login to submit