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
hliu: 2013-04-18 14:48:23

I want to solve this problem by Python , but always get 'NZEC', I can't get it. What's the detailed information about 'NZEC'? i handle the input like this:
==
ca = int(sys.stdin.readline()[0:-1].split()[0])
for i in range(0, ca):
lis = sys.stdin.readline()[0:-1].split()
.....

is it right?

Last edit: 2013-04-18 14:55:21
vipul khullar: 2013-04-18 13:38:40

i have corrrectly solved the problem but have not got any points

Ashutosh Pandey: 2013-04-17 13:30:29

@Goutam Parashar instead of public class name simply class it will work

vipul khullar: 2013-04-16 10:03:34

my solution is correct but getting run time error

Przemys³aw Biernat: 2013-04-11 09:20:37

I use VC++ and my program works fine. If I submit compilation is ok but I get runtime error. Why if on VC++ everything is ok and compilation is ok. Something about use to large memory?

Mitch Schwartz: 2013-04-10 06:55:13

For Java, the submitted file is always run as Main.java, so you can either name your class Main, or you can remove the word public.

Goutam Parashar: 2013-04-10 04:35:48

i am getting this error on submission while its working fine for me.. can some one please tell me y is this coming...

Main.java:6: class Prime_Generator is public, should be declared in a file named Prime_Generator.java
public class Prime_Generator {
^
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

Vijay Dhameliya: 2013-04-09 06:34:57

Can somebody please tell me for which input this solution (<snip>) is giving time limit exceed Please:-(

Last edit: 2022-06-19 12:28:52
Shrinidhi Sondur: 2013-03-29 07:04:53

The simplest way to go about this is the Sieve of Eratosthenes

zbetmen: 2013-03-28 23:09:00

I have implemented segmented sieve of Eratosthenes and I'm getting wrong answer. I've covered even bad input and can't catch what's wrong. Can anybody suggest few good tests?


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