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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Quick ways to check for Prime and find next Prime in Java
- Find coordinates of a prime number in a Prime Spiral
- Prime numbers after prime P with sum S
- Print the nearest prime number formed by adding prime numbers to N
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of 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
- Print prime numbers with prime sum of digits in an array
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Sum of prime numbers without odd prime digits
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Permutation of first N positive integers such that prime numbers are at prime indices
- Count all prime numbers in a given range whose sum of digits is also prime
- Count prime numbers that can be expressed as sum of consecutive prime numbers
- Permutation of first N positive integers such that prime numbers are at prime indices | Set 2
- Efficient program to print all prime factors of a given number
- Almost Prime Numbers
Improved By : Mithun Kumar