Sunday Times Teaser 3285 – Daughters’ Ages
by Bernardo Recamán
Published Sunday September 07 2025 (link)
“How old are your five daughters?” Ignacio asked me.
“Considering their ages as whole numbers, they are all under 20, some of them are the same, and they add up to a prime number,” I answered. “Also, if you were to choose any two of them, no matter which two, their ages would have a common divisor greater than 1.”
“I can’t work out how old they are,” complained Ignacio.
“And you still couldn’t even if I told you the sum of all the ages. However, if I told you how old the youngest and oldest are, then you would be able to work out all the ages,” I responded.
“That’s great, because I now know how old all your daughters are!” Ignacio joyfully said after a pause.
In increasing order, what are the five ages?
-
John Z permalink123456789101112131415161718192021222324252627282930313233343536373839404142from itertools import combinations, combinations_with_replacement as cwrfrom math import gcd#create list of primes < 100 (for sum of ages)prms = [p for p in range(11, 100, 2) if all (p % d for d in (3, 5, 7))]# create dictionary, key = sum of ages: values = list of agesp2ages = dict()# consider 5 possible ages (2 not possible because sum of ages: even)for ages in cwr(range(3, 19), 5):# sum of ages must be primeif (agesum := sum(ages)) not in prms:continue# ages must have a common factor pairwiseif any(gcd(a, b) == 1 for a, b in combinations(ages, 2)):continue# add the list of ages to the dictionaryp2ages[agesum] = p2ages.get(agesum, ()) + ((ages),)#create dictionary, key = (youngest, oldest): values = list of agesyo2loa = dict()# consider all items in dictionary with key = prime sum of agesfor agelists in p2ages.values():# there must be more than one age list associated with prime sumif len(agelists) > 1:# consider the age lists for each prime sumfor al in agelists:# add age list to dictionary indexed by (youngest, oldest)yo2loa[(al[0], al[4])] = yo2loa.get((al[0], al[4]), ()) + (al,)# consider all age listsfor loa in yo2loa.values():# is there a single age list associated with youngest / oldest pair?if len(loa) == 1:print("Ages:", str(*loa)[1:-1])