Find the Most Factors

If given a pad, pencil, and a factor problem years ago, I would have found doing anything else in the world more exciting. Math is not my forte, yet it remains a curiosity. Especially with The Power Of The Computer, performing math exercises is more of an interesting challenge than a mental ordeal.

A few months back, I wrote a Lesson exploring factors, which dovetails into prime numbers. Primes are those numbers with only two factors, the number itself and one. Other numbers along the way have multiple factors, including prime values and others that divide evenly, no remainders.

Some numbers have only a couple of factors. Others are magical and sport many factors. I’m sure a mathematical term exists for such factor-rich numbers. Yet, quickly I grew a desire to discover which values from 1 to 1000 have the highest number of factors. In fact, upon reviewing output of my earlier factor code examples, several values from 1 to 1000 may have an identical number of factors.

Your task for this month’s Exercise is to write code that ferrets out the number of factors for values from 1 to 999. For each value, determine the number of factors. For example, the value 160 has 12 factors: 1, 2, 4, 5, 8, 10, 16, 20, 32, 40, 80, and itself (160). The value 156 also has 12 factors. But what’s the highest value in the given range?

Write code that tallies the factors for values 1 through 999. Examine the list to pull out the value that has the greatest number of factors. It might be that several values have the same number of factors, so ensure that you catch them all.

As a tip, you can use the sample code from the earlier Lesson (link above) to get started, which is what I did. Still, the nature of the program is significantly different that other modifications are in order.

Try this Exercise on your own before you check out my solution.

Leave a Reply