Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with a c++ program with explanation. Im stuck at how to begin and make the functions. Consider the following definitions: A proper

I need help with a c++ program with explanation. Im stuck at how to begin and make the functions.

Consider the following definitions:

  1. Aproper divisorsof a positive integer (2) is any of its divisors excluding the number itself.
  2. For example, the proper divisors of 10 are: 1, 2 and 5.
  3. Aperfect numberis apositiveinteger (2) that is equal to the sum of its properdivisors.
  4. For example, 6 and 28 are perfect numbers, since:
  5. 6=1+2+3
  6. 28 = 1 + 2 + 4 + 7 + 14
  7. Background of perfect numbers:https://en.wikipedia.org/wiki/Perfect_number
  8. Amicable numbersare two different positive integer (2), so related that the sum of the proper divisors of each is equal to the other number.
  9. For example, 220 and 284 are amicable numbers, since:
  10. 284 = 1 + 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110
  11. 220 = 1 + 2 + 4 + 71 + 142
  12. Background of amicable numbers: https://en.wikipedia.org/wiki/Amicable_numbers
  13. using a function:
  14. void analyzeDividors(int num, int& outCountDivs, int& outSumDivs)
  15. The function takes as an input a positive integernum(2), and updates two output parameters with the number ofnum's proper divisors and their sum.
  16. For example, if this function is called withnum=12, since 1, 2, 3, 4 and 6 are 12s proper divisors, the function would update the output parameters with the numbers 5 and 16. Note:Pay attention to the running time of your function. An efficient implementation would run in (num).
  17. Use the function you wrote in section (a), to implement the function:
  18. bool isPerfect(int num)
  19. This function is given a positive integernum(2), and determines if it is a perfect number.
  20. Use the functions you implemented in sections (a) and (b), to make a program that reads from the user a positive integer M (2), and prints:
  • All the perfect numbers between 2 and M.
  • All pairs of amicable numbers between 2 and M (both numbers must be in the range). Note:Pay attention to the running time of your implementation.An efficient algorithm for this part would callanalyzeDividors (M)times all together.
  • Your program should interact with the userexactlyas it shows in the following example:
  • Enter a positive integer >= 2:2000
  • The perfect numbers between 2 and your number are:
  • 6 28 496
  • The pairs of amicable numbers that are between 2 and your number are:
  • 220 284
  • 1184 1210

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

What is biochemistry?

Answered: 1 week ago