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
Jaideep: 2013-05-16 03:10:01

i always get TIME LIMIT exceeded, but my compiler shows less time than 6 seconds.any help ?

LOST: 2013-05-15 10:57:01

.why the hell i am getting runtime error (SIGSEGV).......everytime...i have checkd that there is no array out of bound....

Balázs: 2013-05-13 18:25:19

I'm always getting "time limit exceeded". I'm using C++ with vector at the beginning, then after I'm just using pure arrays, but I'm always getting this! :(

ওয়াসী (Wasi): 2013-05-13 17:42:34

@Kumar Gaurav SIGXFSZ is a sign that you output more than 33MB of data...
Check this link
SPOJ Forum is a good place to solve this type of error

Last edit: 2013-09-18 12:47:24
Kumar Gaurav: 2013-05-13 04:48:08

I also got this one time
runtime error (SIGSEGV)
How to resolve this error....

Kumar Gaurav: 2013-05-13 04:46:31

I am getting this
SIGXFSZ...please explain this

MAYANK BHURA: 2013-05-11 03:20:39

for each of the invalid inputs, do we exit the method or re-accept it using do-while loops?
#java

Amit Kumar Yadav: 2013-05-10 21:10:25

My code is working perfectly fine when I tested by providing the input file exactly in the format required. But I don't how would it work when I submit it. Please let me know, if I shall have the provision to provide the input through file or just keep it run-time.

shantanu mahajan: 2013-05-02 16:12:19

I'm too getting NZEC, using raw_input() and the code seems to be running fine on ideone.com
any ideas?

> MemoryError

Last edit: 2013-05-02 17:12:15
Simon Liang: 2013-04-18 15:19:07

@hliu You can try to hit the "run" link and run your submission on ideone.com and see what the runtime error is.

Try to use raw_input(), and print functions instead of sys.stdin.readline()

It seems to be more efficient.


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