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.

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

hide comments
2015-02-14 13:34:09 Sanjay Gupta
My problem running time is .1 as per IDEone but still Spoj showing time limit exceed so Please suggest me How can i submit solution.

re(vamsi): try to run your code against higher values of m, n. use forum.(post your code there incase you have any further queries)

Last edit: 2015-02-19 12:34:45
2015-02-12 22:12:40 Archit Kapoor
Sooo after 17 attempts, I finally made it.. AC in the 18th attempt...!! Phew..
2015-02-11 19:18:01 Madhav
very good question!!
2015-02-10 17:23:21 beginner
what is the output of :
1
1 1


(Francky) => Just output nothing for such cases. You can output an empty line if you want, as judge ignores extra whitespaces (spaces, new lines, tabs).

Last edit: 2015-02-10 18:11:13
2015-02-06 15:45:44 Felipe
Don't get it.. I'm using Fermat Primality test, joined with a simple division of small prime numbers. Still, I have a TLE!! What can I do?

re(vamsi): you can't pass TL by doing primality tests for all the numbers, try prime seives

Last edit: 2015-02-06 19:53:52
2015-01-22 18:37:00 Abhimanyu Srivastava
i'm getting TLE using Sieve of erasthonesis algo
2015-01-22 02:23:59 Arpan Das
@Binayaka: Can you please tell me what your issue was?
2015-01-21 06:50:44 SHUBHAM GARG
how to decrease the time of your program...?
2015-01-18 15:11:40 KG
Is there a way to know which test case gave a wrong answer to my code? i am getting correct answer for every test case i tried!
2015-01-12 17:38:12 tyra
i m also getting time limit exceeded.............but it runs well on my pc compiler........if someone has any idea about it.....PLZ HELP
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.