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
SANKET MAKHIJA: 2015-02-18 10:54:46

sometimes basic worth it,,, no use of seive..

Siddhant Mishra: 2015-02-15 15:28:20

i am getting a runtime error
http://ideone.com/******
can someone help

(Francky)=> Please use forum for help, as pointed by the notes below.

Last edit: 2015-02-15 16:26:25
Sarvesh Kesharwani: 2015-02-14 15:30:51

use sieve to solve this question naive algo can also solve because of cube

Sanjay Gupta: 2015-02-14 13:34:09

My problem running time is .1 as per IDEone but still Spoj showing time limit exceed so Please suggest me How can i submit solution.

re(vamsi): try to run your code against higher values of m, n. use forum.(post your code there incase you have any further queries)

Last edit: 2015-02-19 12:34:45
Archit Kapoor: 2015-02-12 22:12:40

Sooo after 17 attempts, I finally made it.. AC in the 18th attempt...!! Phew..

Madhav: 2015-02-11 19:18:01

very good question!!

beginner: 2015-02-10 17:23:21

what is the output of :
1
1 1


(Francky) => Just output nothing for such cases. You can output an empty line if you want, as judge ignores extra whitespaces (spaces, new lines, tabs).

Last edit: 2015-02-10 18:11:13
Felipe: 2015-02-06 15:45:44

Don't get it.. I'm using Fermat Primality test, joined with a simple division of small prime numbers. Still, I have a TLE!! What can I do?

re(vamsi): you can't pass TL by doing primality tests for all the numbers, try prime seives

Last edit: 2015-02-06 19:53:52
Abhimanyu Srivastava: 2015-01-22 18:37:00

i'm getting TLE using Sieve of erasthonesis algo

Arpan Das: 2015-01-22 02:23:59

@Binayaka: Can you please tell me what your issue was?


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