PRIME1 - Prime Generator


Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers!

Input

The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.

Output

For every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.

Example

Input:
2
1 10
3 5

Output:
2
3
5
7

3
5
Warning: large Input/Output data, be careful with certain languages (though most should be OK if the algorithm is well designed)

Information

After cluster change, please consider PRINT as a more challenging problem.

hide comments
magnus_007: 2018-08-06 12:15:23

use normal method no need to use sieve or segmented

badtmeez: 2018-08-03 06:58:42

Use segmented sieve.......

chirag74: 2018-08-02 23:03:52

LOL guys i was literally scratching my head trying to apply sieve of erastothenes to find all primes upto billion and some other algorithm. Trust me it wont work cus they dont even test it upto a billion. Just check if the number is a prime each time. LOLOLOL. Man i hate this question. I really wonder why is it in classical?

paresh121: 2018-08-01 16:34:14

how to reduce time to print a number?
when i did'nt used print command code done processing to about 3000 numbers in .038sec but using print it takes 4.78 sec what to do?

division_7: 2018-08-01 16:03:48

This Question is amazing as if it has no answer to it i tried using python,c and cpp even that sieve algo none works only TLE error is there my god.

priyankamani: 2018-08-01 15:28:06

why you are saying the answer is wrong .plz give the test cases

suyashky: 2018-07-31 15:35:14

Do not forget to check 1!

vishalroybitp: 2018-07-29 18:18:25

What the heck.Tried running sqrt(),n,n/2.and guess what still TLE.

danfrown: 2018-07-21 18:36:29

Well god help me. I ran the loop till sqrt(n) till n/2 till n. And guess what? I still get time limit exceeded. I'm using C. Help me... Anyone..?

amoghraj: 2018-07-19 06:20:22

for anyone struggling with time complexity ....check divisibility up to the sqrt(x) instead of x/2 ! worked for me


Added by:Adam Dzedzej
Date:2004-05-01
Time limit:6s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL6