MB1 - PP numbers

PP numbers are prime numbers and palindromes in decimal notation at once. Your task is to find n-th PP number in ascending order. Then calculate product of its non-zero digits - let's call it m - and find m-th prime number in ascending order.


In the first line of input there is one positive integer Z (1 ≤ Z ≤ 1000) which states the number of test cases. Following Z lines contain test cases.

Each test case consists of one positive integer n (1 ≤ n ≤ 113) which states the number of PP number to find.


For each test case print in separate line two numbers: n-th PP number and m-th prime number.





2 3
11 2
3 5

hide comments
Francky: 2013-01-13 22:40:25

Warning : input seems badly formated. But, I don't know where is the problem.
Edit : maybe some empty lines at the end.

Last edit: 2013-01-15 12:08:58
Snehasish Roy ;): 2013-01-13 21:50:36

Piece Of Cake !!! :D

Man Mohan Mishra: 2013-01-03 18:14:19

really nice problem !! :)

Blasters: 2012-12-19 19:55:29

can anyone pl tell the 113 pp no is it 98***

Last edit: 2012-12-19 19:56:48
Erik Lonèarek: 2012-12-08 17:01:21

@Anmol Have you considered input 113? Perhaps you should use long long.

Nic Roets: 2012-03-10 20:27:16

@vivek Let's say approximately 1 in 10 numbers are prime. Then you will need 1130 palindromes. From combinatorics we know that there are 900 palindromes with 5 digits and another 900 with 6 digits. So 5 or 6 digits is a good guess.

Anmol: 2012-01-31 22:03:35

all precalculations correct but gettin wa
please help wid sum i/o

Last edit: 2012-01-31 22:04:52
Hafidh S.A: 2011-12-23 01:27:35

i get same problem with you. any one can tell me

sandeep pandey: 2011-01-30 23:07:25


Last edit: 2011-02-10 12:50:38
sid: 2011-01-12 20:37:41

all possible test cases must be from 1 to 113??....i have checked all d test cases...thn also its shown wrong ovr here

Added by:Maciej Boniecki
Time limit:0.5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU JS-MONKEY
Resource:2nd Warsaw School of Computer Science Programming Championship