在C语言中,预订的数字是什么意思?

2023年 8月 27日 5.6k 0

在C语言中,预订的数字是什么意思?

订婚数是两个数字的对,其除数之和等于另一个数字。

例如 (a, b) 是一对订婚数,如果 s(a) = b + 1 且 s(b) = a + 1,其中 s(b) 是 b 的等分和:等效条件是 σ(a) = σ(b) = a + b + 1,其中 σ 表示除数和函数。

前几对订婚号码为:(48, 75)、(140, 195)、(1050, 1925) )、(1575, 1648)、(2024, 2295)、(5775, 6128)。

所有已知的订婚号码对都具有相反的奇偶性。任何一对相同的奇偶校验数都必须超过 1010。

算法

Step 1: Find the sum of all divisors for both numbers.
Step 2: Finally check if the sum of the divisors of number added by one is equal to the other number or not.
Step 3: If yes, it is a Betrothed number and otherwise not.

登录后复制

Input:a = 48 b = 75
Output:
48 and 75 are Betrothed numbers

登录后复制

解释

48 的约数:1, 2, 3, 4, 6, 8, 12, 16, 24。它们的和是 76。

75 的约数:1 , 3, 5, 15, 25。它们的和是 49。

使用 for 循环并检查从 1 到 a-1 的每个数字。

检查判断是否能整除数字 a ,则循环。如果是,请将此数字添加到 aDivisorSum 中。循环完成后,aDivisorSum 包含 a 的所有除数之和。

类似地,找到第二个数字的所有除数之和并将其保存在 bDivisorSum 中。

现在检查一个数的除数之和是否等于另一个数(无论是否加一)。如果是,请打印出这两个号码都是订婚号码。否则就不是。

示例

 现场演示

#include
int main() {
int i;
int a,b;
int aDivisorSum = 0;
int bDivisorSum = 0;
a=48 ;
b=75 ;
for( i = 1; i < a; i++) {
if(a % i == 0) {
aDivisorSum = aDivisorSum + i;
}
}
for( i = 1; i < b; i++) {
if(b % i == 0) {
bDivisorSum = bDivisorSum + i;
}
}
if(( a+1== bDivisorSum) && (b+1 == aDivisorSum)) {
printf("%d and %d are Betrothed numbers

",a,b);
} else {
printf("%d and %d are not Betrothed numbers

",a,b);
}
}

登录后复制

输出

48 and 75 are not Betrothed numbers

登录后复制

以上就是在C语言中,预订的数字是什么意思?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!

相关文章

如何删除WordPress中的所有评论
检查WordPress服务器磁盘使用情况的7种简便方法(查找大文件和数据)
如何更改WordPress常量FS_METHOD
如何为区块编辑器、Elementor等构建WordPress文章模板
如何彻底地删除WordPress主题及相关内容
如何使用WordPress搭建一个内网

发布评论