Most Divisors

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]




Search WWW


As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.


Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 


We receive a few cents from each purchase.  Thanks


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)


Feedback:  Send an e-mail with your comments about this program (or anything else).

Search only





Problem Description

Which positive 3-digit integer has the most positive integer divisors?

Source:  Based on "2001 Mensa Puzzle Calendar" puzzle for October 13

Background & Techniques

Here's a problem that's simple to solve with a program but not easy with pencil & paper.   There may be a trick to solve it simply by hand, but I haven't found it.  

For this program, we'll just try all integers, n,  from 100 to 999 in a loop and for each n check all divisors from 1 to  n / 2.   To satisfy the requirements of the problem, all we have to do is check the number of divisors found for each n against maxdivisors, the maximum found so far. and save  n and maxdivisors whenever a higher value is found.  

 Delphi's remainder function. mod, is the easy way to check for divisors, if "number mod trialdivisor = 0" then trialdivisor is a divisor.  

We'll add a few more lines of code here to display the divisors, just in case someone wants to check our answer. 

Running/Exploring the Program 

bulletBrowse source extract
bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

What is the maximum number of divisors for 4 digit numbers? 
5 digit numbers?  (Be warned - using this technique for the 5 digits case will execute about a billion trial divisions, so be prepared to wait for a few of minutes.)
How could the algorithm be made faster?  Hint: each successful division should give us 2 divisors and let us lower the upper limit of potential divisors that we need to check.



  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2018, Gary Darby    All rights reserved.