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
hollapr: 2016-05-06 23:37:50

Same logic doesn't work in C and runtime error is shown... Don't use scanf and printf...

cout and cin is working.... Enjoy!!

Last edit: 2016-05-06 23:38:31
boney_412: 2016-05-06 20:29:43

AC!!!!

noxiousav: 2016-05-04 16:51:46

My code works in my ide and also ideone.com but here it says Time limit has exceeded.

d_griffin_101: 2016-05-03 18:40:10

My code works. I use the ide compiler and it works. Yet when I submit it, it says that the time limit has exceeded itself.

ducanswap: 2016-04-25 04:38:42

sol : count all prime numbers smaller than sqrt 1000000000 (31622) so we have an array a(1..3401) of prime nb
for each nb x from m - n, if x mod any nb from array a = 0 then it's not a prime nb

hrithik_sethia: 2016-04-17 12:55:14

help:tle

sushanth: 2016-04-15 12:14:05

Will Fermat primality test work?

jyoti_gambhir: 2016-04-14 11:46:36

my code is running well on my jdk but its giving runtime error on ideone.why is it so?

khouloud1: 2016-04-09 16:55:47

hey; where can i find the evaluation of my code :( ?

adv010: 2016-04-09 06:56:25

TLE!!!!


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