
订婚数是两个数字的对,其除数之和等于另一个数字。
例如 (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 = 75Output: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语言中,预订的数字是什么意思?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1443489.html
微信扫一扫
支付宝扫一扫