View Single Post
  #1 (permalink)  
Old 05-15-2008, 04:15 PM
makkato makkato is offline
Newbie
 
Join Date: May 2008
Posts: 1
Credits: 0
Rep Power: 0
makkato is on a distinguished road
Default Amicable numbers

We have to make a program that finds all the amicable numbers between 1-10000 but I have no idea where to start...I found this pseudo code but it's gibberish to me...any help would be apprieciated. I need to code it in python.

Code:
And the following PseudoCode finds all the Amicable Numbers between two numbers

Procedure Find Amicable Pairs
        Enter Starting Number
        Enter Last Number
        For all the numbers between the Starting Number and Last Number and call this FirstNumber
                Call the Function to add all of the Proper Divisors of the FirstNumber and call this SumOfAllProperDivisorsOfFirstNumber
                Call the Function to add all of the Proper Divisors again this time using SumOfAllProperDivisorsOfFirstNumber and call this SumOfAllProperDivisorsOfSecondNumber
                If SumOfAllProperDivisorsOfFirstNumber is equal to SumOfAllProperDivisorsOfSecondNumber then
                        You found a pair
                End if
        End For Loop
End of Procedure
 
Function Add All Of The Proper Divisors of A Number (call this ANumber)
        Set the initial Running Total to 0
        For all the numbers between 1 and half of ANumber and call this CurrentLoopNumber
                If you divide ANumber with CurrentLoopNumber and the remainder is zero then
                        Add the result to the Running Total
                End If
        End For Loop
        Return the Running Total
End of Function
also I found this....

The following Python language code allows you to check if two numbers are Amicable:
Code:
# Definition of the function
def amicable_numbers(x,y):
    sum_x=0
    sum_y=0
    for i in range(1,x):
        if x%i==0:
            sum_x+=i
 
    for k in range(1,y):
        if y%k==0:
            sum_y+=k
 
    return sum_x==y and sum_y==x
 
# Program body
n_1=int(raw_input('Enter nš 1: '))
n_2=int(raw_input('Enter nš 2: '))
 
if amicable_numbers(n_1,n_2):
    print 'Amicable! :)'
else:
    print 'Not Amicable :('

Last edited by makkato; 05-15-2008 at 04:16 PM. Reason: found something else.
Reply With Quote

Sponsored Links