例如 (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 <stdio.h>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语言中,预订的数字是什么意思?的详细内容。
