IBM Research

PUZZLE   IBM-339

Return of the Superheroes

IBM Research · Ponder This · 2026-07

IBM Ponder This #339 · July 2026

Return of the Superheroes

Continuing the theme of last month, we deal with a movie franchise consisting of n superheroes. They are joined by n 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 f(a,b) to each pairing (a,b) 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 f(a,b) is computed is as follows: Let p be some prime and define a function Ta,b(x)=x2+ax+b (mod p). By setting x0=0 and xn+1=T(xn) we obtain a sequence x0,x1,x2, which eventually repeats. Let f(a,b) be the number of steps until the first repeat happens. i.e. if xn is the first element in the sequence such that there exists m<n for which xn=xm, then f(a,b)=n.

For example, for n=5 and p=101, one possible list of pairings is (1,3),(2,1),(3,4),(4,2),(5,5) which yields the values 14,18,19,22,14 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 n=611 and p=14411

A bonus "*" will be given for finding the optimal n in the range 1<n<N for N=1000 which gives the maximal hero-villain value for n and p=17377.

Solution

Best opened after a real attempt

To be added.