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!


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.


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.


1 10
3 5


Warning: large Input/Output data, be careful with certain languages (though most should be OK if the algorithm is well designed)


After cluster change, please consider PRINT as a more challenging problem.

hide comments
dibid: 2016-05-22 22:07:45

I'm using Sieve of Eratosthenes algorithm but I keep getting TLE! no matter what algorithm I use.

pro_7: 2016-05-21 19:52:09

i am getting TLE tell me how to overcome this problem

arpitsharma: 2016-05-20 19:17:50

Search Sieve of Eratosthenes

n_r1y1t: 2016-05-20 15:55:03

Why is my code showing wrong answer? It's working quite well in ideone. There are no test cases. We can't see the output. Nor can we see the optimized solution. Can anybody help, please?

top_gun007: 2016-05-17 03:29:12

f****** easy

ajit: 2016-05-09 18:49:04

I have issues compiling the code in SPOJ. It works in eclipse though.
I posted a question in stackoverflow. Could someone help me solve this. Thanks.

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


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

My code works in my ide and also 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.

Added by:Adam Dzedzej
Time limit:6s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL 6