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.

hide comments
Rafi Ahmad: 2016-02-12 11:09:10

why its show time limit exceeded
i solved it in php please can anyone give me solution

<?php
$stdin = fopen('php://stdin', 'r');
$testcase = fgets($stdin);
$n=1;
while($n<=$testcase){
$start = fgets($stdin);
$end=fgets($stdin);
if($start==1)
{
$start=2;
}
for($i=$start;$i<$end;$i++){
$flag=0;

for($j=2;$j<$i;$j++){

if($i%$j==0){
$flag=1;
break;
}
}
if($flag==0){
echo $i."\n";
}

}

$n++;

}


fclose($stdin);







?>

Last edit: 2016-02-12 11:09:29
navdeep_singh: 2016-02-10 19:14:56

what is "time limit exceeded" error.

rahulvaidya20: 2016-02-08 20:13:51

Getting SIGSEGV error.....but works fine on any compiler including ideone

dharmbhusan_0: 2016-02-06 07:09:51

where am i rong when i am writting prime generator program on gcc then it is ok but when i am writting on spoj then time limit exceeded shown plz help me

dkumarsingh: 2016-02-01 19:16:50

a silly mistake got me 2 WA... a nice problem....

abd_alrhman: 2016-01-31 12:27:00

how i can show the output of my wrong submission

ulti72: 2016-01-31 08:33:38

What does for every test case means

aktech: 2016-01-29 19:44:31

This may help: http://iamit.in/blog/Spoj-Problem-Small-Factorials-FCTRL2-Explanation-and-Solution/

enessetere: 2016-01-29 09:23:06

is there any chance to see where and what "wrong answer" appears?

sukhadspoj: 2016-01-23 14:33:10

getting sigsegv again and again but code workking fine with ideone


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 PERL 6