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
hemant_360: 2021-07-14 14:28:25

"time limit exceeded" Error is producing

nottarobot: 2021-07-10 13:56:53

can someone share code in c++, i have tried a lot but failed

noob_sagar: 2021-07-02 20:24:57

SEGMENTED SIEVE is the way to go!

amish3: 2021-06-30 05:57:41

Used Segmented Seive. But still getting TLE. Any Idea, what mistake I am doing

asura_mao: 2021-06-15 16:15:33

learn simple sieve and segmented sieve before approaching this problem, it would help a lot.

elite_coder999: 2021-06-01 17:51:05

for prime check from 2 to sqare-root of the range

yash_goel007: 2021-06-01 15:26:39

why is it showing tle if it took only 5 seconds while the given time limit is 6 seconds?

c_parna: 2021-05-24 08:33:40

Used segmented sieve with fast io. Done in 0.01.

stormgamming: 2021-05-22 10:36:13

good question, me AC with pascal

pulkit2099: 2021-05-12 10:35:07

i use seive of eratosthenes why i got tle here


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