Paul L.

asked • 11/24/17

How can I find the lowest number, who's factors add up to exceed N?

How can I find the lowest number, who's factors add up to equal or exceed N?

For example, 48 is the first number where it's factors add up to equal or over 100 with it's factors adding up to 124. So how could I find the answer 48, when given the figure 100

1 Expert Answer

By:

David W. answered • 11/24/17

Tutor
4.7 (90)

Experienced Prof

Paul L.

Many thanks for the answer, that does just what I'm after.

One other question though, what if the sum given is larger, e.g. 1 million? Is there a way to make the program more efficient?
Report

11/25/17

David W.

Multiple considerations:
   1 -  larger numbers mean huge sums, so the data type (long integer?) must be able to accommodate both.
   2.  Now, you trade off human time vs. computer time --
          I had a great discussion with a student this week.  I learned computer programming using punched cards, so we did a very careful "desk check" on coding sheets before submitting the job.  It would be a long time before results came back.  Today, with interactive PCs. it is seconds.  Also, computers are vastly cheaper and people time is significantly more expensive (the minimum wage when I started had just been increased to $1.25/hr).  Most instructors fail to teach the engineering economics of computer use, but it is very important.  When developing small, short programs, you may spend hours (it is also more error-prone) to save a few seconds of computer time --- why?  There is value in learning the techniques, but PLZ keep them in context.
       The two categories of improvements are (1) algorithmic improvements and (2) computer code improvements.  For example, you may add all the numbers from 1 to 1,000.000 or you may use Gauss's formula for the sum of the numbers from 1 to N [that is,  N(N+!)/2).  For computer code improvements, optimizing compilers do thins like moving a static assignment statement outside a loop, computing partial results outside a loop, parallel processing, etc.  Programmers often must use these techniques to improve efficiency (there are books full of these).
 
For this problem, the "guts" of the code takes the bulk of the time -- that is "determine the factors of this number."  Since each positive integer has prime factors, and since each factor of the number is the product of some of those primes, the program may keep an array of primes, use only those primes that are factors, in combination, to form other factors [note: this is just one example of an efficiency improvement).  Of course, no prime larger than N/2 need be considered (why?).
 
      Prime factors of 48:    2   2   2   2   3
 
      Factors of 48:
             1
             2
             3
             2*2
             2*3
             2*2*2
             2*2*3
             2*2*2*2
             2*2*2*3
             2*2*2*2*3
Report

11/25/17

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.