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
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?

TechIcon01: 2014-06-29 16:37:36

I have written code for this in java and by using seive of erastosthenes method for finding primes number.It is running absolutely perfect in my machine.But spoj says its wrong answer ..i have tested by giving big numbers and with 6 testcases as well..any clue?

Last edit: 2014-06-29 16:38:09
[Lakshman]: 2014-06-27 08:41:17

@code_do RTE because of too much memory allocation at run time, max n can be 10^9 and you can allocate this much of memory, Try to learn segmented sieve.


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