Here we will see the Osiris number. An Osiris number is such kind of number that are equal to the sum of permutations of sub-samples of their own digits. Suppose the number is 132. Then if we calculate {12 + 21 + 13 + 31 + 23 + 32} this is also 132. So the number is Osiris number. We have to check whether the given number is Osiris number or not.
Approach is simple. If we analyze the numbers, each digit is occurring twice so they are in ones position and tens position. So we can check by multiplying 11 with them.
Algorithm
isOsirisNumber(n) −
Begin a := last digit b := second digit c := first digit digit_sum := a + b + c if n = (22 * digit_sum), then return true end if return false End
Example
#include using namespace std; bool isOsirisNumber(int n) { int a = n % 10; int b = (n / 10) % 10; int c = n / 100; int sum = a + b + c; if (n == (22 * sum)) { return true; } return false; } int main() { int n = 132; if (isOsirisNumber(n)) cout << "This is Osiris number"; else cout << "This is Not Osiris number"; }
Output
This is Osiris number