Find the sum of all Betrothed numbers up to N | Python3 program to find the Sum of the all Betrothed numbers up to N ; Function to find the Sum of the all Betrothed numbers ; To store the Betrothed numbers ; Calculate sum of number_1 's divisors ; i = 2 because we don 't  want to include  1 as a divisor. ; Sum all Betrothed numbers up to N ; Driver Code
import math NEW_LINE def Betrothed_Sum ( n ) : NEW_LINE INDENT Set = [ ] NEW_LINE for number_1 in range ( 1 , n ) : NEW_LINE INDENT sum_divisor_1 = 1 NEW_LINE i = 2 NEW_LINE while i * i <= number_1 : NEW_LINE INDENT if ( number_1 % i == 0 ) : NEW_LINE INDENT sum_divisor_1 = sum_divisor_1 + i NEW_LINE if ( i * i != number_1 ) : NEW_LINE INDENT sum_divisor_1 += number_1 // i NEW_LINE DEDENT DEDENT i = i + 1 NEW_LINE DEDENT if ( sum_divisor_1 > number_1 ) : NEW_LINE INDENT number_2 = sum_divisor_1 - 1 NEW_LINE sum_divisor_2 = 1 NEW_LINE j = 2 NEW_LINE while j * j <= number_2 : NEW_LINE INDENT if ( number_2 % j == 0 ) : NEW_LINE INDENT sum_divisor_2 += j NEW_LINE if ( j * j != number_2 ) : NEW_LINE INDENT sum_divisor_2 += number_2 // j NEW_LINE DEDENT DEDENT j = j + 1 NEW_LINE DEDENT if ( sum_divisor_2 == number_1 + 1 and number_1 <= n and number_2 <= n ) : NEW_LINE INDENT Set . append ( number_1 ) NEW_LINE Set . append ( number_2 ) NEW_LINE DEDENT DEDENT DEDENT Summ = 0 NEW_LINE for i in Set : NEW_LINE INDENT if i <= n : NEW_LINE INDENT Summ += i NEW_LINE DEDENT DEDENT return Summ NEW_LINE DEDENT n = 78 NEW_LINE print ( Betrothed_Sum ( n ) ) NEW_LINE