在这里,我们将看到Osiris编号。奥西里斯数就是这样一种数,它等于自己数字的子样本的置换总和。假设数字为132。那么,如果我们计算{12 + 21 + 13 + 31 + 23 + 32},这也是132。因此,数字为奥西里斯数。我们必须检查给定的号码是否为Osiris号码。
方法很简单。如果我们分析数字,则每个数字都会出现两次,因此它们处于一个位置和十位数。因此,我们可以通过将它们乘以11来进行检查。
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
#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";
}输出结果
This is Osiris number