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
2021-07-02 20:24:57
SEGMENTED SIEVE is the way to go!
2021-06-30 05:57:41
Used Segmented Seive. But still getting TLE. Any Idea, what mistake I am doing
2021-06-15 16:15:33
learn simple sieve and segmented sieve before approaching this problem, it would help a lot.
2021-06-01 17:51:05
for prime check from 2 to sqare-root of the range
2021-06-01 15:26:39
why is it showing tle if it took only 5 seconds while the given time limit is 6 seconds?

2021-05-24 08:33:40
Used segmented sieve with fast io. Done in 0.01.
2021-05-22 10:36:13
good question, me AC with pascal
2021-05-12 10:35:07
i use seive of eratosthenes why i got tle here
2021-05-03 13:51:07
simple segmented Sieve problem easy to solve
2021-05-03 10:42:00
And also you can use ECPP, but is very complicated.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.