PRINT - Prime Intervals

In this problem you have to print all primes from given interval.

Input

t - the number of test cases, then t lines follows. [t <= 150]
On each line are written two integers L and U separated by a blank. L - lower bound of interval, U - upper bound of interval. [2 <= L < U <= 2147483647] [U-L <= 1000000].

Output

For each test case output must contain all primes from interval [L; U] in increasing order.

Example

Input:

2
2 10
3 7

Output:

2
3
5
7
3
5
7

Added by:Roman Sol
Date:2005-03-28
Time limit:1.223s
Source limit:15000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:ZCon

hide comments
2015-10-18 16:23:57
For info, I just passed using cout and cin with time bellow .5s with C++ (g++5.1).
2015-08-31 18:41:42 Sriharshaa Sammeta
Crazy -> I too just changed my solution of PRIME1 with cout and cin to printf and scanf. It passed. Insane !!!!
2015-08-20 13:20:47 golden_ratio
The time limit is too strict, my solution with a right approach was just not working because I was using cin and cout (even with sync_with_stdio(false)). It got accepted instantly once I used scanf and printf.
In my opinion time-limits should be lenient enough to not reject solution on such grounds or at least it should be mentioned in the problem statement to use Fast I/O.
2015-06-17 11:49:03 ArunAr
Bit wise Optimized Segmented Sieve :) Ac
2015-04-07 23:18:13 Dushyant Singh
@Asheesh Pathak: You can click on 'Ranking' on top right corner of this question or go here
http://www.spoj.com/ranks/PRINT/start=200

Last edit: 2015-04-07 23:18:51
2015-04-07 22:36:29 Asheesh Pathak
Mine runs in 0.59s. How can i see the best solutions for this problem?
2015-03-24 20:55:14 Wik146
I keep getting TLE for this - even outputting primes to stdout for a 1,000,000 range takes 2 secs on my computer...
Is the 1.223s a reasonable limit for this?


(Francky) => There's 10000 users below 0.22s on PRIME1, you should improve your score on PRIME1 before trying PRINT. http://www.spoj.com/ranks/PRIME1/start=10000

Last edit: 2015-03-24 22:49:59
2015-03-17 22:06:26 Petar Bosnjak
Do we need to implement linear time sieve for this problem?
edit : linear implementation of sieve is not neccesary!

Last edit: 2015-03-29 14:06:14
2015-02-11 19:18:22 Madhav
very good question indeed!!
2015-01-02 21:30:10 cegprakash
PRIME1 solution got AC here too o.O
--francky--> Not all ! Naive solution can pass with PRIME1, not here.

Last edit: 2015-01-02 21:33:24
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.