Multiply perfect number | Python3 implementation of the above approach ; Function to find the sum of divisors ; Note that this loop runs till square root of N ; If divisors are equal , take only one of them ; Otherwise take both ; Function to check Multiply - perfect number ; Driver code
import math NEW_LINE def getSum ( n ) : NEW_LINE INDENT sum1 = 0 ; NEW_LINE for i in range ( 1 , int ( math . sqrt ( n ) ) ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT if ( n // i == i ) : NEW_LINE INDENT sum1 = sum1 + i ; NEW_LINE DEDENT else : NEW_LINE INDENT sum1 = sum1 + i ; NEW_LINE sum1 = sum1 + ( n // i ) ; NEW_LINE DEDENT DEDENT DEDENT return sum1 ; NEW_LINE DEDENT def MultiplyPerfectNumber ( n ) : NEW_LINE INDENT if ( getSum ( n ) % n == 0 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT else : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT n = 28 ; NEW_LINE if ( MultiplyPerfectNumber ( n ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT