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, nm<=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 5Warning: 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
balasarius:
20190216 23:24:56
OK confused I ran my Python3 solution on ideone and it works as expected in 0.01s but I run it on spoj and it times out, whats going on. I even set a break for the last setup of values in the stdin to get out of the "for i in sys.stdin:" loop to ensure the loop didn't cause it to hang, but still I get a timeout. I'm missing something here 

sam28:
20190216 17:06:55
T*(nm)*log(n) using millerrabin gets TLE ?? lol weird Last edit: 20190216 17:07:36 

aksr27:
20190212 18:20:08
Don't use seive algo just simply use sqrt(n) complexity prime check on each number. 

nikitakulkarni:
20190206 05:29:37
TLE!!HOW TO OVERCOME IT???????? 

lnediak:
20190126 14:21:23
I literally worked on my sieve, but for 10^9 it could only run in like 13 seconds, so not under 6 seconds :( I resorted to brute force style i * i < n 

simestest:
20190126 00:12:56
Since python is a slow language, shouldn't you choose a faster one? 

sreejeet:
20190125 10:45:54
Since python is a slow language, shouldn't it get more time for execution? 

rouge_raven:
20190121 00:36:33
Having TLE in python should i switch the language 

anirudhg:
20190111 14:55:58
link to solution by sbakic :for those trying with c/c++ https://codeforces.com/blog/entry/18439 

Lokesh Reddy:
20190109 16:40:19
wasted lot of time using sieve sqrt(n) solution works. 
Added by:  Adam Dzedzej 
Date:  20040501 
Time limit:  6s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: NODEJS PERL6 