TWINP - TWIN PRIMES

Twin primes are the pair of prime numbers that differ by two. For example:

  • 3, 5
  • 11, 13
  • 29, 31

The numbers in each pair differ by two.

Input

First line of input consists of T (number of test cases).

Next T lines contains a single number N (indicating the Nth pair of twin primes).

T <= 25, 1 <= N <= 10^5

Output

For every test case output the pair of twin primes in each line separated by a single space.

Example

Input:
3
1
7
11

Output:
3 5
59 61
137 139

(Another tutorial version, with limited source code length, at TWINP2.)


Added by:Avinash
Date:2012-04-07
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own Problem

hide comments
2013-04-18 18:24:48 [Lakshman]
Got AC...I initially I was trying Rabin Miller I think the Twins prime would be less then <100000; when tried all n up to 100000 Used sieve to pass the time limit.
2012-08-30 17:28:22 (Tjandra Satria Gunawan)(曾毅昆)
@numerix: Thanks for your explanation. :-) For me, this problem is hard enough, my submissions give me (6 TLE and 6 WA) finally AC with 1,86s time.
2012-08-30 14:51:51 numerix
@Tjandra: Because it's an easy one. You can get AC with a "normal" (or slightly modified) prime sieve - very straight forward. It could be a classical one if TL and/or SL were stricter.
2012-08-30 11:47:07 (Tjandra Satria Gunawan)(曾毅昆)
why this problem in tutorial? can anyone explain?
2012-04-13 18:57:10 RAJDEEP GUPTA
what is the answer for n=10^5 ?
2012-04-11 18:30:16 sandeep pandey
@numerix:i tried same algorithm for C++ and it pass in .97 sec.
same code in java shows TLE.wht does it mean?
2012-04-11 09:05:29 numerix
@sandeep pandey: If you get TLE with Java, you must optimize your code. There are several Python solutions AC, so it shouldn't be a problem to do it with Java.
2012-04-11 05:19:47 sandeep pandey
@Problem Setter:Plesae increase the TimeLimit for SlowerLanuage(Java).
2012-04-11 05:19:47 Santhana Krishnan
@Francky: Did you hard code the primes ? Your time is insane.
2012-04-11 05:19:47 Francky
It could have been more fun with source limit at 1000B (or even 500B), and 4s time limit for slow langages as Python.
But, nice problem.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.