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
joey18: 2016-05-26 15:15:46

IdeOne says Osec but SPOJ says time exceeded

saisrujan: 2016-05-26 12:29:11

My code was compiled and i got the right answer. But When I upload it into spoj it says compilation error.

dibid: 2016-05-22 22:07:45

I'm using Sieve of Eratosthenes algorithm but I keep getting TLE! no matter what algorithm I use.

Last edit: 2022-06-19 12:16:07
pro_7: 2016-05-21 19:52:09

i am getting TLE tell me how to overcome this problem

arpitsharma: 2016-05-20 19:17:50

Search Sieve of Eratosthenes

n_r1y1t: 2016-05-20 15:55:03

Why is my code showing wrong answer? It's working quite well in ideone. There are no test cases. We can't see the output. Nor can we see the optimized solution. Can anybody help, please?

top_gun007: 2016-05-17 03:29:12

f****** easy

ajit: 2016-05-09 18:49:04

I have issues compiling the code in SPOJ. It works in eclipse though.
I posted a question in stackoverflow. Could someone help me solve this. Thanks.

Last edit: 2022-06-19 12:16:23
hollapr: 2016-05-06 23:37:50

Same logic doesn't work in C and runtime error is shown... Don't use scanf and printf...

cout and cin is working.... Enjoy!!

Last edit: 2016-05-06 23:38:31
boney_412: 2016-05-06 20:29:43

AC!!!!


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