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
admiraldoge: 2015-06-12 05:20:44

look for PRIMALITY TEST in google an you will find the answer for you questions :)

nbisht30: 2015-06-11 20:33:38

Wrong answer coming again and again. signal 25.

ruler: 2015-06-11 15:05:21

thanks @Seven.Martinez

ani_991: 2015-06-11 06:31:17

getting "wrong answer" here repeatedly on submission while the answers are correct for all ranges which I have checked on ideone as well as my netbeans (I wrote it in java). What else could be the possible problems except improper printing and wrong answers ? Please help guys.

nbisht30: 2015-06-11 04:11:24

The size of sieve array is becoming very large in worst case. What to do?

fedegas: 2015-06-10 20:50:09

It's my first time using SPOJ, I put my algorithm on Ideone and it says "Standard input is empty"... Do I have to put some input in my code? I left it open to the user to put the numbers... thanks

kura2: 2015-06-09 22:00:18

@skywinder: don't give up! The language actually doesn't matter, it's the algorithm (and output format). How do I know? I just got "accepted" in 0.33 sec using Ruby.

skywinder: 2015-06-09 20:14:35

Seems it's impossible to pass it on ruby.. Go with C++ or Java, guys!

Last edit: 2015-06-09 20:16:33
nbisht30: 2015-06-09 03:57:56

The size of sieve array is becoming very large in worst case. What to do?

ninja_white: 2015-06-08 05:41:22

Use the primality test, with that finally solved the problem of time, that is the solution and also optimize your code so that no repetition ranges and evaluated .. Greetings
P.S. People need to poye more with tips like I'm giving for example. And they had people who had resolved but did not share a clue. We must be more friendly. Regards


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