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
Green Rosh K S: 2014-07-18 11:31:59

Should the code take care of the given specified limits such as the 1^9 and 10^5? My code is showing wrong answer while it works perfectly for all my test cases. Pls help

Petros Tsialiamanis: 2014-07-16 18:24:26

I have implemented the seive of Eratosthenes but I am getting NZEC error.
<snip>

Last edit: 2022-06-19 12:37:19
Akshay Anand: 2014-07-12 13:43:22

Time limit exceeded ......
Is that has something to do with your net connection as well???

Baojun Wang: 2014-07-10 03:35:49

why below got WA?
<snip>

runs well with all own test cases.

Last edit: 2022-06-19 12:37:24
Mohit Goel: 2014-07-05 22:31:26

I've implemented seive of eratosthenes in java.But here i'm getting NZEC runtime error..Plz somebody help me out..
<snip>

Last edit: 2022-06-19 12:37:28
kumarmantri: 2014-07-05 19:29:20

my code runs fine on ideone.com but here while compiling it shows time limit exceeded, please help, i used perl

Comment: Its after running that it shows time limit exceeded.You'll have to find a less costly way to solve the problem than what your are doing now.

Last edit: 2014-07-13 20:35:48
rushikesh: 2014-07-03 16:39:45

In what way we have to take input and give output
Is it
Input and then immediately output or
First take all inputs and then give output

Shiva Kulshreshtha: 2014-07-02 22:34:35

I used a global array of size 10^6, with Sieve of Eratosthenes, but the judge still says run-time error (sigsegv), someone please help this newbie

AbdalrhmanAtta: 2014-07-02 17:12:50

EASY

velamuri monica: 2014-07-02 10:10:34

when i am trieng in turbo c, ma output is correct. but here the output is wrong. why is it so?


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