# 3-digit Osiris number

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.

Examples:

Input: N = 132
Output: Yes
12 + 21 + 13 + 31 + 23 + 32 = 132

Input: N = 154
Output: No

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach:

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:

## C++

 `// C++ implementation of the approach ` `#include ` `using` `namespace` `std; ` ` `  `// Function that returns true if ` `// n is an Osiris number ` `bool` `isOsiris(``int` `n) ` `{ ` `    ``// 3rd digit ` `    ``int` `a = n % 10; ` ` `  `    ``// 2nd digit ` `    ``int` `b = (n / 10) % 10; ` ` `  `    ``// 1st digit ` `    ``int` `c = n / 100; ` ` `  `    ``int` `digit_sum = a + b + c; ` ` `  `    ``// Check the required condition ` `    ``if` `(n == (2 * (digit_sum)*11)) { ` `        ``return` `true``; ` `    ``} ` ` `  `    ``return` `false``; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``int` `n = 132; ` `    ``if` `(isOsiris(n)) ` `        ``cout << ``"Yes"``; ` `    ``else` `        ``cout << ``"No"``; ` ` `  `    ``return` `0; ` `} `

## Java

 `// Java implementation of the approach ` `class` `GFG ` `{ ` `     `  `// Function that returns true if ` `// n is an Osiris number ` `static` `boolean` `isOsiris(``int` `n) ` `{ ` `    ``// 3rd digit ` `    ``int` `a = n % ``10``; ` ` `  `    ``// 2nd digit ` `    ``int` `b = (n / ``10``) % ``10``; ` ` `  `    ``// 1st digit ` `    ``int` `c = n / ``100``; ` ` `  `    ``int` `digit_sum = a + b + c; ` ` `  `    ``// Check the required condition ` `    ``if` `(n == (``2` `* (digit_sum)*``11``))  ` `    ``{ ` `        ``return` `true``; ` `    ``} ` ` `  `    ``return` `false``; ` `} ` ` `  `// Driver code ` `public` `static` `void` `main(String args[]) ` `{ ` `    ``int` `n = ``132``; ` `    ``if` `(isOsiris(n)) ` `        ``System.out.println(``"Yes"``); ` `    ``else` `        ``System.out.println(``"No"``); ` `} ` `} ` ` `  `// This code is contributed by Akanksha Rai `

## Python3

 `# Python implementation of the approach ` ` `  `# Function that returns true if  ` `# n is an Osiris number ` `def` `isOsiris(n): ` `     `  `    ``# 3rd digit  ` `    ``a ``=` `n ``%` `10` `     `  `    ``# 2nd digit ` `    ``b ``=` `(n``/``/``10``)``%` `10` `     `  `    ``# 1st digit ` `    ``c ``=` `n``/``/``100` ` `  `    ``digit_sum ``=` `a ``+` `b ``+` `c ` ` `  `    ``# Check the required condition ` `    ``if``(n ``=``=` `(``2` `*` `(digit_sum) ``*` `11``)): ` `        ``return` `True` `     `  `    ``return` `False` ` `  `# Driver code ` `if` `__name__ ``=``=` `'__main__'``: ` `    ``n ``=` `132` `    ``if` `isOsiris(n): ` `        ``print``(``"Yes"``) ` `    ``else` `: ` `        ``print``(``"No"``) `

## C#

 `// C# implementation of the approach ` `using` `System; ` ` `  `class` `GFG ` `{ ` `// Function that returns true if ` `// n is an Osiris number ` `static` `bool` `isOsiris(``int` `n) ` `{ ` `    ``// 3rd digit ` `    ``int` `a = n % 10; ` ` `  `    ``// 2nd digit ` `    ``int` `b = (n / 10) % 10; ` ` `  `    ``// 1st digit ` `    ``int` `c = n / 100; ` ` `  `    ``int` `digit_sum = a + b + c; ` ` `  `    ``// Check the required condition ` `    ``if` `(n == (2 * (digit_sum)*11))  ` `    ``{ ` `        ``return` `true``; ` `    ``} ` ` `  `    ``return` `false``; ` `} ` ` `  `// Driver code ` `static` `void` `Main() ` `{ ` `    ``int` `n = 132; ` `    ``if` `(isOsiris(n)) ` `        ``Console.WriteLine(``"Yes"``); ` `    ``else` `        ``Console.WriteLine(``"No"``); ` `} ` `} ` ` `  `// This code is contributed by mits `

## PHP

 ` `

Output:

```Yes
```

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

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.