I would be interested to know how you chose the size of pr_set.

When considering the hcf of pairs of dates it is immediately obvious that the maximum possible value is 97.

When considering the sum of tau values it is not immediately obvious that 2000 is an upper bound.

Best wishes

Tony

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
from itertools import combinations from number_theory import Primes, gcd as hcf, tau # the set of odd primes less than 2000 pr_set = Primes().set(3, 2000) # consider the lowest and highest dated sovereigns for y_lo, y_hi in combinations(range(1900, 2000), 2): # their dates must have a highest common factor # that is an odd prime if hcf(y_lo, y_hi) not in pr_set: continue # consider the number of sovereigns (an odd prime) for ns in Primes().range(3): # calculate the gap between each of the dates inc, r = divmod(y_hi - y_lo, ns - 1) if not inc: break if not r: # the dates for all sovereigns dates = tuple(y_lo + i * inc for i in range(ns)) # all pairs of dates have highest common factors that are odd primes if not all(hcf(a, b) in pr_set for a, b in combinations(dates, 2)): continue # the sum of the numbers of divisors for the dates is an odd prime if sum(tau(y) for y in dates) in pr_set: f, s, l = ', '.join(f"{x}" for x in dates).rpartition(', ') print(f"The dates were {f} and {l}.") |