Question

using python Write a def function “amc” with a positive integer “n” input parameter. It returns...

using python

Write a def function “amc” with a positive integer “n” input parameter. It returns the smallest amicable number greater than “n”. Two different numbers are both amicable if the sum of the proper divisors of each is equal to the other. Any number that's part of such a pair is an amicable number.

Hint: You may want to create a separate function to sum proper divisors.

def amc(n):

Return the smallest amicable number greater than positive integer n.

Every amicable number x has a buddy y different from x, such that the sum of the proper divisors of x equals y, and the sum of the proper divisors of y equals x.

For example, 220 and 284 are both amicable because

1 + 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110 is 284, and 1 + 2 + 4 + 71 + 142 is 220

>>> amc(5)

220

>>> amc(220)

284

>>> amc(284)

1184

>>> r = amc(5000)

>>> r

5020

Homework Answers

Answer #1

CODE

def sumOfDiv(x):

  sum = 1

  for i in range(2, x):

    if x % i == 0:

      sum += i

  return sum

def isAmicable(a, b):

  if sumOfDiv(a) == b and sumOfDiv(b) == a:

    return True

  else:

    return False

def amc(n):

i = n + 1

while i < 10000:

j = 0

while j < 10000:

if isAmicable(i, j):

return i

j += 1

i += 1

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write an Assembley Language.A pair of numbers m and n are called "Perfect Dancing Partners" if...
Write an Assembley Language.A pair of numbers m and n are called "Perfect Dancing Partners" if the sum of all divisors of m (excluding m) is equal to the number n and the sum of all divisors of n (excluding n) is equal to m (with m ≠ n). For example, the numbers 220 and 284 are perfect dancing partners because the only numbers that divide evenly into 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55,...
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function...
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function `g` representing an increasing function g(x) 2) a number `gmin`, and returns an integer `nmin` such that nmin>0 is the smallest integer that satisfies g(nmin)>gmin. test: def g(n): return 2*n print(lowest_integer(g, 10)) Output: 6
For C++: a) Write a function is_prime that takes a positive integer X and returns 1...
For C++: a) Write a function is_prime that takes a positive integer X and returns 1 if X is a prime number, or 1 if X is not a prime number. b) write a program that takes a positive integer N and prints all prime numbers from 2 to N by calling your function is_prime from part a.
Write a function called TaylorSin.m that takes as input an array x, and positive integer N,...
Write a function called TaylorSin.m that takes as input an array x, and positive integer N, and returns the Nth Taylor polynomial approximation of sin(x), centered at a = 0. The first line of your code should read function s = TaylorSin(x,N) HINT: in computing k!, use kfact = k*(k-1)*kfact since you are counting by 2
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT