Skip to content

thevkrant/Amicable-Numbers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Amicable Numbers

Amicable numbers are two different numbers related in such a way that the sum of the proper divisors of each is equal to the other number. The smallest pair of amicable numbers is (220, 284).

Prerequisites

Python 3

How to run the script

Execute

python AmicableNumbers.py

Python Script

import math
def divSum(n):
    result = 0
    
    for i in range(2, int(math.sqrt(n)) + 1):
        if (n % i == 0):
            if (i == int(n/i)):
                result = result + i
            else:
                result = result + (i + int(n/i))
    return (result +1)

def amicable (x,y):
    if (divSum(x) != y):
        return False
    return(divSum(y) == x)

# Driven code
x = 220
y = 284
if (amicable(x, y)):
    print("True")
else:
    print("False")

Output:

True

Author Name

Vikrant