Computer Science, asked by gundapriya2, 6 months ago

digit pairs Gven N three-digit number

Answers

Answered by Anonymous
0

Answer:

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

Explanation:

// C++ implementation of the approach

#include <bits/stdc++.h>

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;

}

Similar questions