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
2013-04-18 13:38:40 vipul khullar
i have corrrectly solved the problem but have not got any points
2013-04-17 13:30:29 Ashutosh Pandey
@Goutam Parashar instead of public class name simply class it will work
2013-04-16 10:03:34 vipul khullar
my solution is correct but getting run time error
2013-04-11 09:20:37 Przemys³aw Biernat
I use VC++ and my program works fine. If I submit compilation is ok but I get runtime error. Why if on VC++ everything is ok and compilation is ok. Something about use to large memory?
2013-04-10 06:55:13 Mitch Schwartz
For Java, the submitted file is always run as Main.java, so you can either name your class Main, or you can remove the word public.
2013-04-10 04:35:48 Goutam Parashar
i am getting this error on submission while its working fine for me.. can some one please tell me y is this coming...

Main.java:6: class Prime_Generator is public, should be declared in a file named Prime_Generator.java
public class Prime_Generator {
^
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
2013-04-09 06:34:57 Vijay Dhameliya
Can somebody please tell me for which input this solution (<snip>) is giving time limit exceed Please:-(

Last edit: 2022-06-19 12:28:52
2013-03-29 07:04:53 Shrinidhi Sondur
The simplest way to go about this is the Sieve of Eratosthenes
2013-03-28 23:09:00 zbetmen
I have implemented segmented sieve of Eratosthenes and I'm getting wrong answer. I've covered even bad input and can't catch what's wrong. Can anybody suggest few good tests?
2013-03-24 11:23:29 ning zhu
why it is showing TEL


Last edit: 2013-03-24 11:24:13
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.