A Right-truncatable prime is a prime which remains prime when the last (“right”) digit is successively removed. For example, 239 is right-truncatable prime since 239, 23 and 2 are all prime. There are 83 right-truncatable primes.
The task is to check whether the given number (N > 0) is right-truncatable prime or not.
Input: 239 Output: Yes Input: 101 Output: No 101 is not right-truncatable prime because numbers formed are 101, 10 and 1. Here, 101 is prime but 10 and 1 are not prime.
The idea is to generate all the primes less than or equal to the given number N using Sieve of Eratosthenes. Once we have generated all such primes, then we check whether the number remains prime when the last (“right”) digit is successively removed.
Related Article:Left-Truncatable Prime
This article is contributed by Rahul Agrawal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Print the nearest prime number formed by adding prime numbers to N
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Quick ways to check for Prime and find next Prime in Java
- Find coordinates of a prime number in a Prime Spiral
- Print prime numbers with prime sum of digits in an array
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check whether the sum of prime elements of the array is prime or not
- Sum of each element raised to (prime-1) % prime
- Sum of prime numbers without odd prime digits
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Prime numbers after prime P with sum S
Improved By : Mithun Kumar