订婚数是两个数字的对,其除数之和等于另一个数字。
例如 (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 <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</p><p>",a,b); } else { printf("%d and %d are not Betrothed numbers</p><p>",a,b); } }
48 and 75 are not Betrothed numbers
以上是在C语言中,预订的数字是什么意思?的详细内容。更多信息请关注PHP中文网其他相关文章!