Find 3 Primes

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

Search

 

Search DelphiForFun.org only

Support DFF

 

If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.

In Association with Amazon.com

 

Support DFF

 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.

 

 

Contact

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

 

Search DelphiForFun.org only

 

 

 

 

Problem Description

Here's a simple little program to solve this problem:  "There is only one set of 3 different two-digit prime numbers with the property that the mean of any two number and of all three are all also prime.  What are the numbers?"

Background & Techniques

There are only  21 two digit primes, so we'll build a array containing them and then select all subsets with 3  numbers to check if the means are also prime numbers.  The mean of any set of n-digit positive integers lies between the smallest and the largest so will also be an n-digit number. This lets us just check if the means are integers and in the 2-digit table of primes. 

 Procedure MakePrimes builds the table of primes by checking integers 11 through 99 that no smaller prime divides  it evenly.  It calls function IsPrime to perform this test, (B divides A evenly if (A div B)*B=A where "div" is the integer divide operation which returns an integer quotient ignoring any remainders.)  Function IsPrimeInteger takes a sum. M,  and the number of integers summed, K, as parameters and returns true if K divides M (i.e. the mean is an integer) and M div K is in the array of 2-digit primes.  It returns false otherwise. 

100 or so lines of code make this an Intermediate level program.       

Running/Exploring the Program 

bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

???

 

Original:  November 17, 2010

Modified:  November 17, 2010

 

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