TCS OA-12 2024
Problem Description
Write a program that accepts two integers, n and m, and prints all prime numbers between n and m (inclusive) such that the sum of their digits is also a prime number.
Input Format
The first line contains two integers n and m.
Output Format
Print all prime numbers between n and m (inclusive) such that the sum of their digits is also a prime number.
Constraints
- 1 ≤ X, Y ≤ 10⁴
Example
Sample Input:
10 30
Sample Output:
11
23
29
Explanation:
- 11: Prime and the sum of digits 1+1= 2 (which is prime).
- 23: Prime and the sum of digits 2+3= 5 which is prime).
- 29: Prime and the sum of digits 2+9= 11 (which is prime).
- Other prime numbers like 13, 17, 19, and 31 are excluded because their digit sums are not prime.