Ponder This Challenge - September 2026 - Loeschian Arithmetic Progressions
- Ponder This
Continuing the theme of last month, we deal with a movie franchise consisting of superheroes. They are joined by supervillains. The producers intend to pair the superheroes and the supervillains to form (hero, villain) pairs where each hero has a unique villain serving as their nemesis.
Each pairing is accepted differently by the audiences. After elaborate work, a method of assigning numerical value to each pairing to estimate the audiences' reaction was developed. The producers wish to find the list of pairings that maximizes the value of the pairing with the minimal value in the list. This minimal value is called the hero-villain value.
The way is computed is as follows: Let be some prime and define a function . By setting and we obtain a sequence which eventually repeats. Let be the number of steps until the first repeat happens. i.e. if is the first element in the sequence such that there exists for which , then .
For example, for and , one possible list of pairings is which yields the values for which the minimum is 14. It turns out that every list of pairings gives a value of at most 14, so 14 is hero-villain value for this case.
Your goal Find the hero-villain value for and
A bonus "*" will be given for finding the optimal in the range for which gives the maximal hero-villain value for and .
The numerical solutions are 349 for the main riddle, and for the bonus (giving the hero-villain value 408). Every giving the value 408 was accepted; by "optimal" we only meant "giving the maximum hero-villain value for in this range".
Each pairing is a permutation, and so the riddle can be rephrased in the following manner: Given some matrix, pick values not sharing row or column, such that the smallest value among them is as large as possible. This is one variant of a bottleneck assignment problem. Similar to the previous superhero problem, the key for solving this is graph matching.
To actually find the hero-villain value we use binary search. For a given , we attempt to determine whether there is some permutation giving at least by constructing a bipartite graph where a hero is matched with a villain only if their value is at least . All that remains is finding a perfrect matching in this graph, which can be solved using the Hopcroft-Karp algorithm which was useful in the previous superhero riddle as well.