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
Divyansh Shukla: 2016-03-12 10:42:54

Miller Rabin rocks

vtejak: 2016-03-08 14:05:36

getting a error of time limit exceeded can anyone help

shrutivtu: 2016-03-06 16:31:18

my prog is taking too much time here plz help

fluffybottoms: 2016-03-03 09:09:07

code runs in <2 seconds with highest possible complexity on my machine but i get a TLE running the code on here. is the problem broken or something?

xcepti0n: 2016-03-01 07:07:40

what if there is no prime no between two given nos ? then what should it print?should it give two empty lines or just one?

luongvanvinh95: 2016-02-29 07:01:20

abc. . .xyz

Last edit: 2016-02-29 07:01:51
ongfa_02: 2016-02-28 16:32:04

My code works fine on ideone but when I submit ,it says wrong answer.What should I do?

codingzo17: 2016-02-23 19:56:56

@navdeep_singh http://www.spoj.com/tutorials/USERS/

shreyaasridhar: 2016-02-22 17:30:26

My code works fine on IDLE, ideone python but it still says wrong answer

Seshadri R: 2016-02-16 05:19:30

@Rafi Ahmad: I have no idea on how PHP compares with C/C++/Java in run time efficiency. But, your algorithm needs lot of sprucing. You should start testing only from an odd number and test only odd numbers (every iteration should increment the previously tested number ($i) by two). Secondly, instead of dividing each $i by all numbers till $i - 1, it should be divided by all prime numbers less than or equal to square root of $i. So, this requires an array that is filled with every prime number that your program finds.

Last edit: 2016-02-16 05:20:16

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