Betrothed numbers in C?


Betrothed numbers are pair of two numbers in a way that the sum of their divisors when added by is equal to another number.

For example (a, b) are a pair of betrothed numbers if s(a) = b + 1 and s(b) = a + 1, where s(b) is the aliquot sum of b: an equivalent condition is that σ(a) = σ(b) = a + b + 1, where σ denotes the sum-of-divisors function.

The first few pairs of betrothed numbers are: (48, 75), (140, 195), (1050, 1925), (1575, 1648), (2024, 2295), (5775, 6128).

All known pairs of betrothed numbers have opposite parity. Any pair of the same parity must exceed 1010.

Algorithm

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

Explanation

Divisors of 48 : 1, 2, 3, 4, 6, 8, 12, 16, 24. Their sum is 76.

Divisors of 75 : 1, 3, 5, 15, 25. Their sum is 49.

Use  for loop and check for each numbers starting from 1 to a-1.

Check for each number in the loop if it can divide the number a or not. If yes, add this number to the aDivisorSum. After the loop complets, aDivisorSum contains the sum of all the divisors for a.

Similarly, find the sum of all divisors for the second number and save it in bDivisorSum.

Now check if the sum of divisors of one number is equal to the other number by adding one in it or not. If yes, print that both are Betrothed numbers. Otherwise they are not.

Example

 Live Demo

#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);    } }

Output

48 and 75 are not Betrothed numbers

Updated on: 04-Oct-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements