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.

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

hide comments
2021-11-03 19:00:32
I have time error ((:
2021-11-03 17:02:57
time limit exceeded= program is Heavy and overly complex solution

Last edit: 2021-11-03 18:21:42
2021-11-01 19:25:03
co to jest runtime error (NZEC)
2021-10-20 20:20:02
I'm getting correct output. Judge still not accepting?
2021-09-29 13:28:54
ideone is also showing success and with timelimits , but solution is Status bar shows Time limit exceeded . Anyone else facing the same issue
2021-09-23 22:30:29
I'm not sure how the judging system works here. Is it accepting only a predetermined solution, for example here the segmented sieve(which I only now looked up what is), or it accepts a few type of solutions? Because my code works perfectly and gives the exact required output, but I get "wrong answer" all the time for this problem.
2021-08-16 15:02:16
<snip>
on spoj compilation error, but compilation has no errors

[NG]: Your main() is defined as int but doesn't return anything.

Last edit: 2021-08-16 22:43:35
2021-07-29 10:29:00
Getting TLE, how to deal with it?
2021-07-28 16:14:56
easy
2021-07-20 10:34:14
learning segmented sieve is good , but there is a simpler solution.
you can simply make a function that gets an integer as an input and checks it is prime or not and returns false or true.
then write a for loop and generate all numbers from a to b (to inputs of probleme) and give them to is prime function that you made before . if it returns true , print the number.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.