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
2014-12-17 21:23:46 Andreas
Hi! I may be dumb, but I don't get the Input. Should I read it in with an input-method or is it given by a file? And how are the m and n given?

--ans(Francky)--> Before PRIME1, please consider TEST that best suit for a first problem to be solved ; a solution will provided if you get trouble for input/output method.
edit: it seems you already solved TEST. IO are the same on SPOJ ; standard IO.

Last edit: 2014-12-17 22:02:06
2014-12-17 01:41:40 tasteless_wine
my file size limit is execiding can u take me out from this
2014-12-17 00:13:26 Shoumya Kanti Das
The best solutions for this problem shows runtime of 0.0s . How is that possible??
2014-12-16 06:36:30 Ken Ramsey
I used fortran. To any other fortran users, note that you may experience many compilation errors. SPOJ uses gfortran with some GNU extensions that may reject your code for a while until you figure it out. You have to make trivial adjustments, but sadly you're going to have to accept a higher number of compilation errors in your score than you'd like.
2014-12-16 06:23:54 Ken Ramsey
Manan, your program is exceeding the time limit because you are doing a primality test on each number in the given interval. While accurate, that approach is simply too slow. I suggest that you look into the Sieve of Eratosthenes. I used a segmented version of this sieve and it worked fine. A program based on this method is going to spend a lot more time printing out the answer of large intervals than it is in calculating that answer.
2014-12-13 10:30:39 Manan
Can anybody look at the code and identify why it is telling time limit exceeded. <snip>

Last edit: 2022-06-19 12:39:02
2014-12-12 14:03:43 dipankar gupta
done......!!!!!
2014-12-10 08:40:06 Anonymous
FINALLY....found out the bug..thanks SPOJ :)
2014-12-10 08:30:59 Anonymous
My solution is showing SIGSEGV. I have tested my code for most extreme cases on my system and it runs fine...but problem persists with SPOJ. Any suggestions?
2014-12-08 16:10:03 Anonymous
What is the problem with my code? I know its brute force...but my answer is correct. And SPOJ is just not accepting it...why??

Thanks :)

(Reply by Min_25)
Please see the Notes below.
> 1. Don't post any source code here.
> 3. For more discussion (hints, ideas, solutions) please visit our forum.

Last edit: 2014-12-08 16:55:14
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.