Given an integer N, the task is to find the probability that a number with a number of digits as N is a palindrome.
The number may have leading zeros.
Input: N = 5
Output: 1 / 100
Input: N = 6
Output: 1 / 1000
- As leading zeroes are allowed total number of N digit number is 10N.
- A number is a palindrome when first N/2 digits match with last N/2 digits in reverse order.
- For even number of digits, we can pick first N/2 digits and then duplicate them to form the rest of N/2 digits so we can choose (N)/2 digits.
- For an odd number of digits we can pick first (N-1)/2 digits and then duplicate them to form the rest of (N-1)/2 digits so we can choose (N+1)/2 digits.
- So the probability that an N digit number is palindrome is 10ceil( N / 2 ) / 10N or 1 / 10floor( N / 2 )
Below is the implementation of the approach:
- Sum of all N digit palindrome numbers
- Count of N-digit Palindrome numbers
- Largest palindrome which is product of two n-digit numbers
- Count of Numbers in Range where first digit is equal to last digit of the number
- Find the remainder when First digit of a number is divided by its Last digit
- Largest number less than N with digit sum greater than the digit sum of N
- Probability such that two subset contains same number of elements
- Random number generator in arbitrary probability distribution fashion
- Check if a number with even number of digits is palindrome or not
- Queries on sum of odd number digit sums of all the factors of a number
- Number of times a number can be replaced by the sum of its digits until it only contains one digit
- Largest number less than N whose each digit is prime number
- Count the number of occurrences of a particular digit in a number
- Check if a number is Palindrome
- Given a number, find the next smallest palindrome
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.