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
Himanshu Gholap: 2014-12-30 09:46:49

I am getting "time limit exceeding", i my using C, what mistake am i probably making?
<snip>

Last edit: 2022-06-19 12:39:35
Giovanny Escobar: 2014-12-30 06:21:17

Neeraj Dwivedi, compile using C++ 4.8.1, it works!

Last edit: 2014-12-30 06:21:56
Samarth Agarwal: 2014-12-29 20:04:50

How much time should it take in Milliseconds to find prime numbers within range 999900000-1000000000? Mine takes 1490ms only. Is anybody's algo faster?

--ans(Francky)--> You should try PRINT to confront faster codes.
edit : I've add an information in description for other users.

Last edit: 2014-12-29 20:45:42
Neeraj Dwivedi: 2014-12-27 09:44:22

plz help to correct my runtime error <snip>

Last edit: 2022-06-19 12:39:30
Parth: 2014-12-26 17:44:26

Can someone please point out why I'm getting the time limit exceeded error. I've used the sieve of eratosthenes algorithm.
<snip>

Last edit: 2022-06-19 12:38:35
vivek: 2014-12-21 14:33:44

Since, the time to print the answer is more than the actiual calculation of the answer, any hints on that side.

Ketan Sethi: 2014-12-20 10:18:34

My solution is showing NZEC. I have tested my codE and it runs fine. Any suggestions will be really appreciable
<snip>

Last edit: 2022-06-19 12:38:57
Leetao: 2014-12-20 07:43:30

to my surprise,this problem is so easy.why was correctrate so low?

Last edit: 2014-12-20 08:22:36
Andreas: 2014-12-17 21:23:46

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
tasteless_wine: 2014-12-17 01:41:40

my file size limit is execiding can u take me out from this


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