Sphere Online Judge

SPOJ Problem Set (classical)

2. Prime Generator

Problem code: PRIME1


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)
Added by:Adam Dzedzej
Date:2004-05-01
Time limit:6s
Source limit:50000B
Memory limit:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All except: NODEJS PERL 6

hide comments
2014-07-21 07:51:12 Zarif Hossain
Can I know the time limit???
2014-07-20 16:00:01 [Lakshman]
@Aragon!!! Your algorithm is wrong. Do you know how to check a number is prime or not. And your assumption that if number is not divisible by 3,5,7 is prime is wrong.

Last edit: 2014-07-20 16:01:27
2014-07-20 14:26:01 Aragon!!!
can anyone tell whats wrong in my algo.. its giving proper out for me? http://ideone.com/joDXHu
2014-07-18 11:31:59 Green Rosh K S
Should the code take care of the given specified limits such as the 1^9 and 10^5? My code is showing wrong answer while it works perfectly for all my test cases. Pls help
2014-07-16 18:24:26 Petros Tsialiamanis
I have implemented the seive of Eratosthenes but I am getting NZEC error.
http://ideone.com/HvtUHE
2014-07-12 17:16:30 Jhon Cena
No@akshay anand
2014-07-12 13:43:22 Akshay Anand
Time limit exceeded ......
Is that has something to do with your net connection as well???
2014-07-10 03:35:49 Baojun Wang
why below got WA?

http://ideone.com/e.js/Uauik6

runs well with all own test cases.
2014-07-06 02:15:59 Mustafa Kaood
,m
2014-07-05 22:31:26 Mohit Goel
I've implemented seive of eratosthenes in java.But here i'm getting NZEC runtime error..Plz somebody help me out..
http://ideone.com/hwF4Sk
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.