订婚的数字是两个数字对,其乘数之和等于另一个数字。
例如,如果s(a)= b +1和s(b)= a +1,则(a,b)是一对订婚数,其中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。
用于循环并检查从1到a-1的每个数字。
检查循环中的每个数字是否可以将数字相除。如果是,则将此数字添加到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\n",a,b);
   } else {
      printf("%d and %d are not Betrothed numbers\n",a,b);
   }
}输出结果
48 and 75 are not Betrothed numbers