Check if a number can be expressed as sum two abundant numbers | Python 3 program to check if number n is expressed as sum of two abundant numbers ; Function to return all abundant numbers This function will be helpful for multiple queries ; To store abundant numbers ; to store sum of the divisors include 1 in the sum ; if j is proper divisor ; if i is not a perfect square ; if sum is greater than i then i is a abundant numbe ; Check if number n is expressed as sum of two abundant numbers ; if both i and n - i are abundant numbers ; can not be expressed ; Driver code
from math import sqrt NEW_LINE N = 100005 NEW_LINE def ABUNDANT ( ) : NEW_LINE INDENT v = set ( ) ; NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT sum = 1 NEW_LINE for j in range ( 2 , int ( sqrt ( i ) ) + 1 ) : NEW_LINE INDENT if ( i % j == 0 ) : NEW_LINE INDENT sum += j NEW_LINE DEDENT if ( i / j != j ) : NEW_LINE INDENT sum += i // j NEW_LINE DEDENT DEDENT if ( sum > i ) : NEW_LINE INDENT v . add ( i ) NEW_LINE DEDENT DEDENT return v NEW_LINE DEDENT def SumOfAbundant ( n ) : NEW_LINE INDENT v = ABUNDANT ( ) NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( list ( v ) . count ( i ) and list ( v ) . count ( n - i ) ) : NEW_LINE INDENT print ( i , " ▁ " , n - i ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( - 1 ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 24 NEW_LINE SumOfAbundant ( n ) NEW_LINE DEDENT