Given a 3-digit number N, the task is to find if N is an Osiris number or not. Osiris numbers are the numbers that are equal to the sum of permutations of sub-samples of their own digits. For example, 132 is an Osiris number as it is equal to 12 + 21 + 13 + 31 + 23 + 32.
Input: N = 132
12 + 21 + 13 + 31 + 23 + 32 = 132
Input: N = 154
If n = 132,
132 = 12 + 21 + 13 + 31 + 23 + 32
132 = 2 * 11 + 2 * 22 + 2 * 33
132 = 22 + 44 + 66
132 = (2 + 4 + 6) * 11
132 = 2 * (1 + 2 + 3) * 11, each digit of 132 occurs twice in the ones and tens position of the sums.
The same rule applies for every 3-digit Osiris number and can be reciprocated to check whether a number is an Osiris number or not.
For a 3-digit number N to be considered as an Osiris number, N must be equal to 2 * (sum of digits) * 11
Below is the implementation of the above approach:
Time Complexity: O(1)
Space Complexity: O(1)
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Number of factors of very large number N modulo M where M is any prime number
- Count number of triplets with product equal to given number with duplicates allowed
- Count number of trailing zeros in Binary representation of a number using Bitset
- Find minimum number to be divided to make a number a perfect square
- Count number of triplets with product equal to given number with duplicates allowed | Set-2
- Find the largest number smaller than integer N with maximum number of set bits
- Minimum divisor of a number to make the number perfect cube
- Number of distinct ways to represent a number as sum of K unique primes
- Number of ways to split a binary number such that every part is divisible by 2
- Minimum number of swaps required to make a number divisible by 60
- Number of possible permutations when absolute difference between number of elements to the right and left are given
- Given number of matches played, find number of teams in tournament
- Find smallest possible Number from a given large Number with same count of digits
- Find the minimum number to be added to N to make it a prime number
- Largest number dividing maximum number of elements in the array
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.