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-03-16 08:07:47 Utkarsh
No need to implement the sieve algorithm. After 6 WA, changed a bit in the basic approach (optimized it) and got it ACCEPTED . If you need any help mail me at utkarshg******@gmail.com. Language used : C++.

(Francky) => If someone need any help, the forum is the well designed place.

Last edit: 2015-03-16 09:54:52
2015-03-15 19:01:40 shiva
my program for prime generator works fine but i am facing time limit exceeded problem. i have tested my program on ideone.com but when i try it spoj.com it says time limit exceeded. can anybody help me ??
2015-03-11 17:13:33 `Ak
till now it is passing without sieve so pls reduce the time limit
2015-03-09 03:50:45 maria reinzo
I give up, I'll go ask around somewhere else. I'm not getting the activation email at all.

Last edit: 2015-03-09 03:57:02
2015-03-06 08:47:10 Abhinandan Agarwal
Finally in 0.01 time :-)
2015-03-04 15:10:22 Shubham Mohanka
@ron tle (time limit exceeded) is an error in case when ur program is not fast enough to complete in the given time limit.try using a faster algorithms.if u r a beginner,i will suggest u to google faster primality testing algos.hope that answers ur query.
this might help - http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=primalityTesting
cheers :)

Last edit: 2015-03-04 15:11:21
2015-03-04 07:49:08 ron
my program does what the problem is asking for but when I submit it shows TLE. can someone tell me why TLE?
2015-03-02 16:51:58 fordex
whats the best algorithm to generate primes between any two numbers?

Last edit: 2015-03-02 16:52:41
2015-02-28 15:03:48 Nootan R
SHOWING WRONG ANSWER
2015-02-21 06:43:42 Shashank kumar
no need of seives ...just read an article on wikipedia...about primality test http://en.wikipedia.org/wiki/Primality_test
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.