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
sakib_muhit: 2015-12-29 21:04:56

#xpshekhar sir, between 1 to 50, 35 & 49 can be made in form of 6*n -1 or 6*n +1 ;bt they r not prime.. :(

xpshekhar: 2015-12-29 18:23:51

always remember
all prime number except 2 and 3 will be either in the form 6*n-1 or 6*n+1.
ac in one go :)

tssan: 2015-12-23 19:26:53

I'm having runtime error too (NZEC) using C#, I checked it on ideone.com and my local env - works fine, looks like maybe input is not provided?

dlpcoder: 2015-12-23 11:09:28

Again and again runtime error! No any WA or error on my local pc (using g++4.8).

dupletor: 2015-12-19 07:02:37

Well... It has to be optimized for being accepted... Required a step for finding primes lowe than the higher number square root and another for comparing the numbers between them with those primes.

Last edit: 2015-12-19 08:02:04
gomathi ganesan: 2015-12-19 07:00:55

Getting TLE with sieve of Eratosthenes.

surecode: 2015-12-17 22:03:47

I keep getting WA. I checked my solution with Ideone and local PC, but see no problems. I working in JAVA. Is there any way to get a better clue as to what my problem is?

yash_1997: 2015-12-17 16:27:47

I keep on getting time limit exceeded.
Please help!

imkiran: 2015-12-16 09:18:02

what could be the reason for runtime error ?

kartik_dtu: 2015-12-15 19:43:25

Lookup segmented sieve on geeksforgeeks


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