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
nikitakulkarni: 2019-02-06 05:29:37

TLE!!HOW TO OVERCOME IT????????

lnediak: 2019-01-26 14:21:23

I literally worked on my sieve, but for 10^9 it could only run in like 13 seconds, so not under 6 seconds :( I resorted to brute force style i * i < n

simestest: 2019-01-26 00:12:56

Since python is a slow language, shouldn't you choose a faster one?

sreejeet: 2019-01-25 10:45:54

Since python is a slow language, shouldn't it get more time for execution?

rouge_raven: 2019-01-21 00:36:33

Having TLE in python should i switch the language

Lokesh Reddy: 2019-01-09 16:40:19

wasted lot of time using sieve sqrt(n) solution works.

harshuraj2710: 2018-12-21 04:28:16

TLE....WHAT TO DO?

seantang001: 2018-12-19 05:39:10

works in terminal. i think my problem is with the io. can figure out why they format it this way.(python)

amit9bhasita_: 2018-12-05 02:36:42

the approach to problem i almost same for all. you have to run a loop for n then scan l and r and further check whether num is prime or not. but the magic doesnt appear there as it relies in what condition you put in the loop to check prime. the ideal one is run a loop such that for(int k=2;k*k<NUM;K++) this is the actual magic which can take you from tle. also the real magic stays back in printing numbers for that you have to use fast io , can google it for how to use . i recommend using string builder inside all for loops and finally print. fast io can be simply found on internet

Last edit: 2018-12-05 02:42:08
aashish_a2z: 2018-11-28 09:06:46

You can simply run two loops one for each number from m to n and one to check whether that number is prime or not....You can run the another loop from 2 to sqrt(number) ans as u got any number which divides number then increase temp variable and use break and check if temp is greater then 1 then number is prime


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