





















Continuing the theme of last month, we deal with a movie franchise consisting of nn superheroes. They are joined by nn 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)f(a,b) to each pairing (a,b)(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)f(a,b) is computed is as follows: Let pp be some prime and define a function Ta,b(x)=x2+ax+b (mod p)T_{a,b}(x)=x^2+ax+b\ (\text{mod}\ p). By setting x0=0x_0=0 and xn+1=T(xn)x_{n+1}=T(x_n) we obtain a sequence x0,x1,x2,…x_0,x_1,x_2,\ldots which eventually repeats. Let f(a,b)f(a,b) be the number of steps until the first repeat happens. i.e. if xnx_n is the first element in the sequence such that there exists m<nm<n for which xn=xmx_n=x_m, then f(a,b)=nf(a,b)=n.
For example, for n=5n=5 and p=101p=101, one possible list of pairings is (1,3),(2,1),(3,4),(4,2),(5,5)(1,3), (2,1), (3,4), (4,2), (5,5) which yields the values 14,18,19,22,1414, 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=611n=611 and p=14411p=14411
A bonus "*" will be given for finding the optimal nn in the range 1<n<N1<n<N for N=1000N=1000 which gives the maximal hero-villain value for nn and p=17377p=17377.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。