All Tracks Math Number Theory Primality Tests Problem

Prime Minister's number
Tag(s):

Medium

Problem
Editorial
Analytics

Our Prime Minister has some secret numbers, so as in any case of emergency he can use it to contact the Avengers to save him. But these numbers has some special features, they are prime and sum of each individual's digit is also prime.Like 23, it is prime number and sum of it's digits (2+3)= 5, is also a prime number.

For your information, Avengers are Earth's Mightiest Heroes , consisting of Iron Man, Captain America, Thor, Hulk and many more.

So your task is to print all the such numbers  in a given range, a,b (both included), in ascending order.

Save your PM.

Input:

Single line containing two space separated integers, a and b respectively.

Output:

All the integers between a to b (including a and b), that satisfy conditions mentioned in statement, separated by single space.

Constraints:

1<= a,b <=1000000

SAMPLE INPUT
10 50
SAMPLE OUTPUT
11 23 29 41 43 47
Explanation

Sample Input:

10 50

Sample Output:

11 23 29 41 43 47

Explanation:

Here a=10, b=50.

All the numbers between these which satisfy the property explained in question are

11 23 29 41 43 47, in ascending order.

11 (1+1=2 is prime)

23 (2+3=5 is prime)

29 (2+9=11 is prime)

41 (4+1=5 is prime)

43 (4+3=7 is prime)

47 (4+7=11 is prime)

Time Limit: 4.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

通知
View All Notifications

?