Given a number x, find it’s palindromic selfie number according to selfie multiplicative rule. If such a number doesn’t exist, then print “No such number exists”.
A Palindromic selfie number satisfies the selfie multiplicative rule such that there exists another number y with x * reverse_digits_of(x) = y * reverse_digits_of(y), with the condition that the number y is obtained by some ordering of the digits in x, i.e x and y should have same digits with different order.
Input : 1224 Output : 2142 Explanation : Because, 1224 X 4221 = 2142 X 2412 And all digits of 2142 are formed by a different permutation of the digits in 1224 (Note: The valid output is either be 2142 or 2412) Input : 13452 Output : 14532 Explanation : Because, 13452 X 25431 = 14532 X 23541 And all digits of 14532 are formed by a different permutation of the digits in 13452 Input : 12345 Output : No such number exists Explanation : Because, with no combination of digits 1, 2, 3, 4, 5 could we get a number that satisfies 12345 X 54321 = number X reverse_of_its_digits
- The idea is to break down the number and obtain all permutations of the digits in the number.
- Then, the number and its palindrome are removed from the set of permutations obtained, which will form the LHS of our equality.
- To check for RHS, we now iterate over all other permutations equating
LHS = current_number X palindrome(current_number)
- As soon as we get a match, we exit the loop with an affirmative message, else print “No such number available”.
Below is implementation of above approach :
Palindrome multiplicative selfie of 145572 is : 157452 Given number has no palindrome selfie. Palindrome multiplicative selfie of 4669 is : 6496
- Generate all palindromic numbers less than n
- Sum of all odd length palindromic numbers within the range [L, R]
- Make palindromic string non-palindromic by rearranging its letters
- Longest Palindromic Substring using Palindromic Tree | Set 3
- C++ program to find all numbers less than n, which are palindromic in base 10 and base 2.
- Minimum cuts required to convert a palindromic string to a different palindromic string
- Palindromic Primes
- Longest Non-palindromic substring
- Number of palindromic permutations | Set 1
- Longest Palindromic Substring | Set 2
- Longest Palindromic Subsequence | DP-12
- Lexicographically first palindromic string
- Print all palindromic partitions of a string
- Number of palindromic paths in a matrix
- Check if all the palindromic sub-strings are of odd length
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Rajput-Ji