Define $K_N=\displaystyle\prod_{j=1}^N(j!)^j$. Write $K_{236}=19^E U$, where $19\nmid U$. Let $Z$ be the least nonnegative residue of $E+U$ modulo $997$. Define $P(x)=x^{5} - 9 x^{4} + 349 x^{3} - 3 x^{2} + 7 x$ and $Q(x)=x^{4} + 692 x^{2} + 8 x - 63$. Find the least nonnegative residue modulo $1000$ of the resultant $\operatorname{Res}_x(P,Q)$.

Answer: 929


Let $Z$ be the least nonnegative residue modulo $1000$ of the number of reduced fractions $a/b$ that satisfy $\frac{1}{5}<a/b<\frac{3}{5}$, $1\le b\le 554$, $\omega(b)=2$, and $a+b\equiv 1\pmod{7}$. Here $\omega(b)$ is the number of distinct prime divisors of $b$. Let $p=1361$, let $A$ and $B$ be the least nonnegative residues modulo $p$ of $128Z+288$ and $1345Z+304$, respectively, and consider $E: y^2=x^3+Ax+B$ over $\mathbb F_p$. Including the point at infinity, let $C=\#E(\mathbb F_p)$, and let $X$ be the sum, as ordinary integers, of the $x$-coordinates of all affine points of $E$. Find the least nonnegative residue of $C+3X$ modulo $1000$.

Answer: 835


A partition of $\{1,2,\ldots,9\}$ has a crossing quadruple when $a<b<c<d$, the numbers $a,c$ lie in one block, and $b,d$ lie in a different block. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of set partitions that have exactly $4$ blocks, exactly $0$ singleton blocks, and a number of crossing quadruples congruent to $2$ modulo $5$. Put $L=Z+43$. Let $S(n,k)$ be a Stirling number of the second kind, and let $A(n,j)$ be the number of permutations of $\{1,\ldots,n\}$ with exactly $j$ descents. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum_{j=0}^{5}(j+1)S(L+j,6)A(L,j)2^j$.

Answer: 284


Let $C_{253}=\frac1{254}\binom{506}{253}$ be a Catalan number. Write $C_{253}=5^e u$ with $5\nmid u$. Let $Z$ be the least nonnegative residue of $u+84e$ modulo $1000$. Write $Z=100d_2+10d_1+d_0$ with $0\le d_0,d_1,d_2\le9$. Let $\lambda=(12+d_2+d_1+d_0,8+d_1+d_0,4+d_0,4,2)$. Find the least nonnegative residue modulo $1000$ of the number of standard Young tableaux of shape $\lambda$.

Answer: 192


Consider standard Young tableaux of skew shape $(4,2,2,2,2)/(0,0,0,0,0)$. A descent is an integer $i$ for which the entry $i+1$ lies in a lower row than the entry $i$. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of such tableaux that have exactly $5$ descents. Put $L=18+(Z\bmod 13)$ and, for $1\le j\le L$, put $a_j=1+((Zj^2+12j+3)\bmod 14)$. If $[a_1;a_2,\ldots,a_L]=p_L/q_L$ and $p_{L-1}/q_{L-1}=[a_1;\ldots,a_{L-1}]$ are in lowest terms, find the least nonnegative residue modulo $1000$ of $p_L+q_L+5p_{L-1}+7q_{L-1}$.

Answer: 24


A tournament is formed by orienting every edge of the complete graph on $7$ labeled vertices. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of tournaments that have sorted outdegree sequence $(1, 1, 1, 4, 4, 5, 5)$ and exactly $3$ directed $3$-cycles. A Markov chain has transition matrix $\frac1{11}\begin{pmatrix}3 & 3 & 4 & 1\\2 & 7 & 1 & 1\\4 & 3 & 3 & 1\\8 & 1 & 1 & 1\end{pmatrix}$. It starts in state $2$. After $Z+55$ steps, the probability that it is in one of the states $\{3,4\}$ is $p/q$ in lowest terms with $q>0$. Find the least nonnegative residue of $p+q$ modulo $1000$.

Answer: 771


Let $\theta_k=\frac{2\pi k}{19}$ for $1\le k\le 18$. If $\displaystyle\sum_{k=1}^{18}\left(\frac1{(8-2\cos\theta_k)^2}+\frac{2}{8-2\cos\theta_k}\right)=\frac pq$ in lowest terms, let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Let $m=8+(Z\bmod 9)$. Form a wheel with hub $0$ and rim vertices $1,2,\ldots,m$ in cyclic order. Give spoke $0j$ weight $1+((Z+j^2+9j)\bmod5)$ and rim edge $j(j+1)$ weight $1+((2Z+4j+j^2)\bmod5)$, with $m+1$ interpreted as $1$. The weight of a spanning tree is the product of its edge weights. Find the total weight of all spanning trees modulo $1000$.

Answer: 525


Let $Z$ be the least nonnegative residue modulo $1000$ of the number of $5\times5$ zero-one matrices that have every row sum equal to $2$ or $3$, exactly $1$ rows of sum $3$, no zero column, rank $4$ over $\mathbb F_2$, trace $3$, an anti-diagonal sum congruent to $0$ modulo $3$, and exactly $5$ columns of odd sum. Find the least nonnegative residue modulo $1000$ of the number of words of length $Z+53$ over $\{0,1,2\}$ that contain none of the blocks $012$, $121$, $210$, have digit sum congruent to $3$ modulo $5$, and contain a number of $2$'s congruent to $2$ modulo $4$.

Answer: 702


Define $K_N=\displaystyle\prod_{j=1}^N(j!)^j$. Write $K_{195}=11^E U$, where $11\nmid U$. Let $Z$ be the least nonnegative residue of $E+U$ modulo $997$. Put $L=Z+30$. Define $G(n,0)=1$, $G(0,k)=0$ for $k>0$, and $G(n,k)=G(n-1,k)+7^{n-k}G(n-1,k-1)$. Find the least nonnegative residue modulo $1000$ of $G(L,11)+3G(L,10)$.

Answer: 208


On an $8\times 8$ board, row $i$ contains exactly the first $b_i$ allowed squares, where $(b_1,\ldots,b_8)=(1, 2, 3, 7, 8, 8, 8, 8)$. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of ways to place $8$ nonattacking rooks, one in each row and column, so that exactly $4$ rooks lie on the main diagonal, the induced column permutation has inversion parity $1$, and $\sum_{i=1}^8 i\pi(i)\equiv 5\pmod{8}$. Let $n=7+(Z\bmod 4)$ and let $M=(m_{ij})_{0\le i,j<n}$, where $m_{ij}$ is the least nonnegative residue modulo $17$ of $i^2+10ij+j^2+5Z(i+j+1)+6Z+8\,[i-j\equiv1\pmod n]$. Here the bracket equals $1$ when its condition holds and $0$ otherwise. Find the least nonnegative residue of $\det M$ modulo $1000$.

Answer: 447


Let $Y(x)$ be the unique formal power series with constant term $0$ satisfying $Y=x(1+Y)^{2}(1+Y^2)^{3}(1-Y)^{-1}$. Let $Z$ be the least nonnegative residue modulo $997$ of the coefficient of $x^{36}$ in $Y(x)^{10}$. Let $R$ be the least nonnegative residue modulo $10^{10}-1$ of $19^{Z^2+3Z+86}+31^{Z+86}+4510209742$, and write $R$ as a block of exactly ten decimal digits, allowing leading zeros. For $0\le j<10$, let $R_j$ be the integer obtained by cyclically shifting this block left by $j$ places. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum (j+1)\gcd(R_j,10^{10}-1)$, where the sum is over the integers $j$ with $0\le j<10$ and $R_j\equiv 6\pmod{19}$.

Answer: 135


Let $N=6452641$. For all coprime positive integer pairs $(x,y)$ with $x>y$ and $x^2-xy+y^2=N$, consider those satisfying $2x-y\equiv 11\pmod{13}$. Let $Z$ be the least nonnegative residue modulo $1000$ of the sum of $3x+y$ over all such pairs. Define $u_0=81$ and $u_1=458$, and for $k\ge 0$ define $u_{k+2}$ by $u_{k+2}\equiv 11u_{k+1}+9u_k+12(-1)^k\pmod{1000}$, with every $u_k$ chosen from $\{0,1,\ldots,999\}$. Find the least nonnegative residue modulo $1000$ of $u_{Z^2+9Z+87}+13u_{2Z+43}$.

Answer: 545


Let $Y(x)$ be the unique formal power series with constant term $0$ satisfying $Y=x(1+Y)^{2}(1+Y^2)^{3}(1-Y)^{-1}$. Let $Z$ be the least nonnegative residue modulo $991$ of the coefficient of $x^{43}$ in $Y(x)^{10}$. Let $p=2129$, let $A$ and $B$ be the least nonnegative residues modulo $p$ of $611Z+422$ and $1387Z+870$, respectively, and consider $E: y^2=x^3+Ax+B$ over $\mathbb F_p$. Including the point at infinity, let $C=\#E(\mathbb F_p)$, and let $X$ be the sum, as ordinary integers, of the $x$-coordinates of all affine points of $E$. Find the least nonnegative residue of $C+5X$ modulo $1000$.

Answer: 723


Over the ring $(\mathbb Z/1000\mathbb Z)[x]$, let $c_0+c_1x+\cdots+c_6x^6$ be the remainder when $(x^2+x^4+3)^{154655378506}$ is divided by the monic polynomial $P(x)=x^{7} - 5 x^{6} - 6 x^{5} - 5 x^{4} - 2 x^{3} - 5 x - 5$. Let $Z$ be the least nonnegative residue of $9c_0+1c_1+2c_2+7c_3+5c_4+2c_5+9c_6$ modulo $1000$. Set $T=11^{Z+1}+\displaystyle\sum_{k=0}^Z(-1)^k\binom Zk13^k23^{Z-k}(k^3+5k^2+7k+2)$. Find the least nonnegative residue of $T$ modulo $1000$.

Answer: 611


Let $Z$ be the least nonnegative residue modulo $1000$ of the number of reduced fractions $a/b$ that satisfy $\frac{1}{5}<a/b<\frac{3}{5}$, $1\le b\le 466$, $\omega(b)=1$, and $a+b\equiv 6\pmod{13}$. Here $\omega(b)$ is the number of distinct prime divisors of $b$. Let $n=7+(Z\bmod 4)$ and let $M=(m_{ij})_{0\le i,j<n}$, where $m_{ij}$ is the least nonnegative residue modulo $23$ of $i^2+15ij+j^2+15Z(i+j+1)+11Z+14\,[i-j\equiv1\pmod n]$. Here the bracket equals $1$ when its condition holds and $0$ otherwise. Find the least nonnegative residue of $\det M$ modulo $1000$.

Answer: 171


Let $Z$ be the least nonnegative residue modulo $1000$ of the number of $5\times5$ zero-one matrices that have every row sum equal to $2$ or $3$, exactly $5$ rows of sum $3$, no zero column, rank $4$ over $\mathbb F_2$, trace $2$, an anti-diagonal sum congruent to $0$ modulo $3$, and exactly $5$ columns of odd sum. Put $L=Z+48$. Let $S(n,k)$ be a Stirling number of the second kind, and let $A(n,j)$ be the number of permutations of $\{1,\ldots,n\}$ with exactly $j$ descents. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum_{j=0}^{5}(j+1)S(L+j,6)A(L,j)11^j$.

Answer: 69


An urn contains $11$ red, $11$ blue, and $10$ green balls. Balls are drawn uniformly without replacement until the number drawn of some color first reaches its threshold: $5$ for red, $4$ for blue, and $2$ for green. The probability that the stopping color is green and the total number of draws is congruent to $3$ modulo $4$ is $p/q$ in lowest terms. Let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. In the quotient ring $(\mathbb Z/1000\mathbb Z)[x]/(x^{5}-3x^{4}-6x^{2}-4x+6)$, write $(-x^{4}-4x^{3}+5x^{2}+3x+4)^{Z^2+11Z+41}=r_0+r_1x+r_2x^2+r_3x^3+r_4x^4$. Find the least nonnegative residue modulo $1000$ of $4r_0+2r_1+6r_2+4r_3+9r_4$.

Answer: 205


Triangle $ABC$ has side lengths $BC=21$, $CA=15$, and $AB=16$. An interior point $P$ has barycentric coordinates $(8:7:3)$, and $Q$ is the isotomic conjugate of $P$. The perpendiculars from $Q$ to $BC,CA,AB$ meet those lines at $D,E,F$, respectively. If $([DEF]/[ABC])^2=p/q$ in lowest terms, let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Let $p=1657$, set $x_0=Z$, and for $k\ge0$ let $x_{k+1}$ be the least nonnegative residue modulo $p$ of $x_k^2+1399x_k+351$. Find the least nonnegative residue modulo $1000$ of $x_{10^{12}+13Z+71}+7\displaystyle\sum_{j=0}^{Z+44}x_j$.

Answer: 376


For a positive integer $t$, let $J_2(t)=t^2\prod_{p\mid t}(1-p^{-2})$. Let $N=780$. Let $Z$ be the least nonnegative residue modulo $997$ of $\displaystyle\sum (d+1)J_2(N/d)$, where the sum is over squarefree divisors $d$ of $N$ such that $d\equiv 1\pmod{11}$ and $\Omega(d)\equiv 1\pmod2$. A Markov chain has transition matrix $\frac1{14}\begin{pmatrix}4 & 3 & 6 & 1\\5 & 1 & 7 & 1\\1 & 1 & 4 & 8\\1 & 6 & 3 & 4\end{pmatrix}$. It starts in state $2$. After $Z+41$ steps, the probability that it is in one of the states $\{1,3\}$ is $p/q$ in lowest terms with $q>0$. Find the least nonnegative residue of $p+q$ modulo $1000$.

Answer: 115


Answer: 475


Answer: 967


Let $N=38909$. Among all pairs of positive integers $(x,y)$ satisfying $x<y$, $x^2+y^2=N$, and $\gcd(x,y)=1$, retain only those for which $x+2y\equiv 1\pmod{13}$. Let $Z$ be the least nonnegative residue modulo $1000$ of $\displaystyle\sum(2x+3y)$ over the retained pairs. Put $L=Z+50$. Let $S(n,k)$ be a Stirling number of the second kind, and let $A(n,j)$ be the number of permutations of $\{1,\ldots,n\}$ with exactly $j$ descents. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum_{j=0}^{9}(j+1)S(L+j,10)A(L,j)11^j$.

Answer: 65


For $0\le i,j\le5$, define $m_{ij}=\binom{29+i+j}{23+2i-j}+3\binom{29+i+j}{23-i+2j}+3\binom{29+i+j}{23+i-j-2}$, where a binomial coefficient is $0$ when its lower index is outside its usual range. If $M=(m_{ij})_{0\le i,j\le5}$, let $Z$ be the least nonnegative residue of $\det M$ modulo $991$. A Markov chain has transition matrix $\frac1{13}\begin{pmatrix}1 & 1 & 1 & 10\\1 & 4 & 4 & 4\\2 & 1 & 9 & 1\\2 & 3 & 6 & 2\end{pmatrix}$. It starts in state $2$. After $Z+78$ steps, the probability that it is in one of the states $\{3,4\}$ is $p/q$ in lowest terms with $q>0$. Find the least nonnegative residue of $p+q$ modulo $1000$.

Answer: 149


On an $8\times 8$ board, row $i$ contains exactly the first $b_i$ allowed squares, where $(b_1,\ldots,b_8)=(2, 3, 6, 8, 8, 8, 8, 8)$. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of ways to place $8$ nonattacking rooks, one in each row and column, so that exactly $0$ rooks lie on the main diagonal, the induced column permutation has inversion parity $1$, and $\sum_{i=1}^8 i\pi(i)\equiv 2\pmod{5}$. Put $H=Z+107$. Find the least nonnegative residue modulo $1000$ of the number of ordered pairs $(a,b)$ that satisfy $1\le a<b\le H$, $\gcd(a,b)=1$, $a+b\equiv 5\pmod{11}$, and $\left\lfloor Ha/b\right\rfloor\equiv 4\pmod{5}$.

Answer: 145


Let $C_{267}=\frac1{268}\binom{534}{267}$ be a Catalan number. Write $C_{267}=5^e u$ with $5\nmid u$. Let $Z$ be the least nonnegative residue of $u+28e$ modulo $1000$. Put $L=Z+70$. Let $S(n,k)$ be a Stirling number of the second kind, and let $A(n,j)$ be the number of permutations of $\{1,\ldots,n\}$ with exactly $j$ descents. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum_{j=0}^{7}(j+1)S(L+j,8)A(L,j)5^j$.

Answer: 900


For $1\le n\le 72793$, set $a_n=\lfloor n\sqrt{12}\rfloor$ and $b_n=\lfloor n/\sqrt{12}\rfloor$. Let $Z$ be the least nonnegative residue modulo $1000$ of the sum of all $n$ such that $a_n\equiv 2\pmod{11}$, $b_n\equiv 4\pmod{6}$, and $n\equiv 1\pmod2$. Let $L=Z+52$ and $P=\displaystyle\prod_{j=1}^L(8j+7)$. Write $P=5^eU$ with $5\nmid U$, and let $u$ be the least nonnegative residue of $U$ modulo $5^5=3125$. Find the least nonnegative residue modulo $1000$ of $u+7e+2(e\bmod 5)^2$.

Answer: 546


Let $p=3079$. A number $g$ with $1<g<p$ is called admissible when it is a primitive root modulo $p$, the sum of its base-$11$ digits is congruent to $5$ modulo $11$, and the sum of the base-$11$ digits of its least positive inverse modulo $p$ is congruent to $9$ modulo $10$. Let $Z$ be the least nonnegative residue modulo $1000$ of the sum of all admissible $g$. Let $n=7+(Z\bmod 4)$ and let $M=(m_{ij})_{0\le i,j<n}$, where $m_{ij}$ is the least nonnegative residue modulo $17$ of $i^2+14ij+j^2+3Z(i+j+1)+4Z+2\,[i-j\equiv1\pmod n]$. Here the bracket equals $1$ when its condition holds and $0$ otherwise. Find the least nonnegative residue of $\det M$ modulo $1000$.

Answer: 460


Two walkers move simultaneously on the lattice, each taking one unit north or east step per second. The lower walker goes from $(0,0)$ to $(9,11)$, and the upper walker goes from $(0,2)$ to $(9,13)$. After every equal number of steps, their current vertices must be distinct. A turn is a change of direction by either walker. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of ordered pairs of walks of such paths that have exactly $20$ turns in total and have the lower path visit exactly $2$ vertices on the line $y=x$, counting its initial vertex. Put $L=Z+64$. For an integer $q\ge2$, let $P_q(L)$ be the number of rotation classes of aperiodic length-$L$ words over a $q$-letter alphabet. Find the least nonnegative residue modulo $1000$ of $P_6(L)+2P_5(L)+\varphi(L)$, where here $q=6$.

Answer: 55


Let $N=30240$. Consider nondecreasing $4$-tuples of integers $2\le a_1\le\cdots\le a_4$ whose product is $N$. Among those having exactly $2$ even entries, greatest common divisor $1$, and $a_1+\cdots+a_4\equiv 4\pmod{6}$, let $Z$ be the least nonnegative residue modulo $1000$ of the sum of all possible values of $a_4$. Let $R$ be the least nonnegative residue modulo $10^{10}-1$ of $11^{Z^2+6Z+69}+29^{Z+69}+2519666299$, and write $R$ as a block of exactly ten decimal digits, allowing leading zeros. For $0\le j<10$, let $R_j$ be the integer obtained by cyclically shifting this block left by $j$ places. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum (j+1)\gcd(R_j,10^{10}-1)$, where the sum is over the integers $j$ with $0\le j<10$ and $R_j\equiv 10\pmod{19}$.

Answer: 17


A sphere $\Sigma$ is orthogonal to four spheres having, respectively, center $(-8,5,-7)$ and squared radius $\frac{221}{2}$; center $(-5,-1,4)$ and squared radius $\frac{133}{2}$; center $(-6,8,-6)$ and squared radius $\frac{177}{2}$; and center $(1,3,-5)$ and squared radius $\frac{11}{2}$. If the center of $\Sigma$ is $(h,k,\ell)$ and its squared radius is $\rho$, and $h^2+k^2+\ell^2+\rho=p/q$ in lowest terms, let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Put $L=Z+31$. Define $G(n,0)=1$, $G(0,k)=0$ for $k>0$, and $G(n,k)=G(n-1,k)+7^{n-k}G(n-1,k-1)$. Find the least nonnegative residue modulo $1000$ of $G(L,9)+3G(L,8)$.

Answer: 413


In triangle $ABC$, the side lengths opposite $A,B,C$ are $26,32,12$, respectively. An interior point $P$ has barycentric coordinates $(5:2:2)$, and $Q$ is the isogonal conjugate of $P$. If $PQ^2=p/q$ in lowest terms, let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. In the quotient ring $(\mathbb Z/1000\mathbb Z)[x]/(x^{5}+5x^{4}+3x^{3}+6x^{2}+5x-3)$, write $(-2x^{4}+3x^{3}-4x^{2}-x-2)^{Z^2+10Z+101}=r_0+r_1x+r_2x^2+r_3x^3+r_4x^4$. Find the least nonnegative residue modulo $1000$ of $-3r_0-5r_1-5r_2+9r_3+4r_4$.

Answer: 9


Let $r_1,r_2,r_3,r_4$ be the roots of $P(x)=x^{4} + 7 x^{3} - 3 x^{2} - 3 x + 7$. For $i<j$ define $u_{ij}=r_ir_j+4$. Let $Z$ be the least nonnegative residue modulo $1000$ of $\displaystyle\sum_{i<j}\left(u_{ij}^{1282}-7u_{ij}^{1281}\right)$. Let $L=Z+47$ and $P=\displaystyle\prod_{j=1}^L(16j+9)$. Write $P=5^eU$ with $5\nmid U$, and let $u$ be the least nonnegative residue of $U$ modulo $5^4=625$. Find the least nonnegative residue modulo $1000$ of $u+13e+2(e\bmod 4)^2$.

Answer: 945


Write the base-$7$ expansion of $1/83$ as $0.\overline{d_1d_2\cdots d_h}_{7}$ with the shortest possible period, and read subscripts cyclically modulo $h$. For each $j$, let $B_j$ be the base-$7$ integer with digits $d_j,d_{j+1},\ldots,d_{j+6}$. Let $Z$ be the least nonnegative residue modulo $1000$ of the sum of all $j\in\{1,\ldots,h\}$ for which $B_j\equiv 3\pmod{15}$ and $d_{j+7}+2d_{j+8}+3d_{j+9}+4d_{j+10}\equiv 6\pmod{9}$. Put $L=Z+66$. Define $G(n,0)=1$, $G(0,k)=0$ for $k>0$, and $G(n,k)=G(n-1,k)+2^{n-k}G(n-1,k-1)$. Find the least nonnegative residue modulo $1000$ of $G(L,8)+3G(L,7)$.

Answer: 828


Consider ordered pairs $(x,y)$ of least positive residues modulo $1296$ satisfying $xy\equiv 701\pmod{1296}$, $x+y\equiv 8\pmod{14}$, and $x+2y\equiv 4\pmod{5}$. Let $Z$ be the least nonnegative residue modulo $1000$ of $\displaystyle\sum(x+3y)$ over all such pairs. Find the least nonnegative residue modulo $1000$ of the number of words of length $Z+60$ over $\{0,1,2\}$ that contain none of the blocks $102$, $11$, $201$, have digit sum congruent to $5$ modulo $9$, and contain a number of $2$'s congruent to $1$ modulo $4$.

Answer: 124


Let $N=329509$. For all coprime positive integer pairs $(x,y)$ with $x>y$ and $x^2-xy+y^2=N$, consider those satisfying $2x-y\equiv 7\pmod{9}$. Let $Z$ be the least nonnegative residue modulo $1000$ of the sum of $3x+y$ over all such pairs. A Markov chain has transition matrix $\frac1{10}\begin{pmatrix}4 & 2 & 2 & 2\\2 & 3 & 2 & 3\\7 & 1 & 1 & 1\\3 & 1 & 3 & 3\end{pmatrix}$. It starts in state $1$. After $Z+33$ steps, the probability that it is in one of the states $\{2,4\}$ is $p/q$ in lowest terms with $q>0$. Find the least nonnegative residue of $p+q$ modulo $1000$.

Answer: 887


Let $C_{315}=\frac1{316}\binom{630}{315}$ be a Catalan number. Write $C_{315}=3^e u$ with $3\nmid u$. Let $Z$ be the least nonnegative residue of $u+81e$ modulo $1000$. Define $u_0=402$ and $u_1=422$, and for $k\ge 0$ define $u_{k+2}$ by $u_{k+2}\equiv 19u_{k+1}-17u_k+7(-1)^k\pmod{1000}$, with every $u_k$ chosen from $\{0,1,\ldots,999\}$. Find the least nonnegative residue modulo $1000$ of $u_{Z^2+11Z+60}+7u_{2Z+12}$.

Answer: 192


Let $p=2017$. A number $g$ with $1<g<p$ is called admissible when it is a primitive root modulo $p$, the sum of its base-$10$ digits is congruent to $7$ modulo $9$, and the sum of the base-$10$ digits of its least positive inverse modulo $p$ is congruent to $3$ modulo $9$. Let $Z$ be the least nonnegative residue modulo $1000$ of the sum of all admissible $g$. Set $T=7^{Z+1}+\displaystyle\sum_{k=0}^Z(-1)^k\binom Zk11^k5^{Z-k}(k^3+7k^2+8k-9)$. Find the least nonnegative residue of $T$ modulo $1000$.

Answer: 759


A sphere $\Sigma$ is orthogonal to four spheres having, respectively, center $(7,5,4)$ and squared radius $\frac{521}{4}$; center $(6,3,7)$ and squared radius $\frac{617}{4}$; center $(-6,-3,-6)$ and squared radius $\frac{133}{4}$; and center $(-6,4,7)$ and squared radius $\frac{441}{4}$. If the center of $\Sigma$ is $(h,k,\ell)$ and its squared radius is $\rho$, and $h^2+k^2+\ell^2+\rho=p/q$ in lowest terms, let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Write $Z=100d_2+10d_1+d_0$ with $0\le d_0,d_1,d_2\le9$. Let $\lambda=(13+d_2+d_1+d_0,9+d_1+d_0,5+d_0,4,2)$. Find the least nonnegative residue modulo $1000$ of the number of standard Young tableaux of shape $\lambda$.

Answer: 800


Over the ring $(\mathbb Z/1000\mathbb Z)[x]$, let $c_0+c_1x+\cdots+c_6x^6$ be the remainder when $(x^2+x^3-2)^{110460296634}$ is divided by the monic polynomial $P(x)=x^{7} + x^{6} + 4 x^{5} - 4 x^{4} + 4 x^{3} - 5 x^{2} + 2 x + 2$. Let $Z$ be the least nonnegative residue of $1c_0+7c_1+4c_2+4c_3+9c_4+2c_5+7c_6$ modulo $1000$. Let $m=8+(Z\bmod 9)$. Form a wheel with hub $0$ and rim vertices $1,2,\ldots,m$ in cyclic order. Give spoke $0j$ weight $1+((Z+j^2+2j)\bmod5)$ and rim edge $j(j+1)$ weight $1+((2Z+j+j^2)\bmod5)$, with $m+1$ interpreted as $1$. The weight of a spanning tree is the product of its edge weights. Find the total weight of all spanning trees modulo $1000$.

Answer: 864


Over the ring $(\mathbb Z/1000\mathbb Z)[x]$, let $c_0+c_1x+\cdots+c_6x^6$ be the remainder when $(x^1+x^5+2)^{267703890501}$ is divided by the monic polynomial $P(x)=x^{7} + 5 x^{6} + 6 x^{5} - 6 x^{4} + 2 x^{3} - 5 x^{2} + x + 4$. Let $Z$ be the least nonnegative residue of $9c_0+2c_1+2c_2+4c_3+7c_4+1c_5+4c_6$ modulo $1000$. Write $Z=100d_2+10d_1+d_0$ with $0\le d_0,d_1,d_2\le9$. Let $\lambda=(12+d_2+d_1+d_0,8+d_1+d_0,4+d_0,4,2)$. Find the least nonnegative residue modulo $1000$ of the number of standard Young tableaux of shape $\lambda$.

Answer: 720


Let $\theta_k=\frac{2\pi k}{9}$ for $1\le k\le 8$. If $\displaystyle\sum_{k=1}^{8}\left(\frac1{(8-2\cos\theta_k)^2}+\frac{4}{8-2\cos\theta_k}\right)=\frac pq$ in lowest terms, let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Let $p=1889$, set $x_0=Z$, and for $k\ge0$ let $x_{k+1}$ be the least nonnegative residue modulo $p$ of $x_k^2+268x_k+1184$. Find the least nonnegative residue modulo $1000$ of $x_{10^{12}+7Z+59}+5\displaystyle\sum_{j=0}^{Z+54}x_j$.

Answer: 923


A plane partition in an $3\times 5\times 4$ box is a $3\times 5$ array $(p_{ij})$ of integers from $0$ through $4$ that is weakly decreasing across every row and down every column. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of such arrays that have total sum congruent to $2$ modulo $5$, diagonal sum $\sum_{i=1}^{\min(3,5)}p_{ii}\equiv 3\pmod4$, and exactly $0$ entries equal to $4$. Define $u_0=468$ and $u_1=581$, and for $k\ge 0$ define $u_{k+2}$ by $u_{k+2}\equiv 17u_{k+1}-11u_k+12(-1)^k\pmod{1000}$, with every $u_k$ chosen from $\{0,1,\ldots,999\}$. Find the least nonnegative residue modulo $1000$ of $u_{Z^2+3Z+85}+7u_{2Z+36}$.

Answer: 36


A simple graph on $6$ labeled vertices is chosen uniformly from all connected such graphs. The probability that it has exactly $2$ vertices of odd degree and exactly $4$ triangles is $p/q$ in lowest terms. Let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Find the least nonnegative residue modulo $1000$ of the number of words of length $Z+34$ over $\{0,1,2\}$ that contain none of the blocks $010$, $021$, $120$, have digit sum congruent to $3$ modulo $9$, and contain a number of $2$'s congruent to $4$ modulo $5$.

Answer: 13


The eight vertices of a cube are colored red, green, or blue, using the colors exactly $2, 5, 1$ times, respectively. Two colorings are considered the same when a rotation of the cube carries one to the other. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of equivalence classes that have exactly $6$ edges whose endpoints have the same color. Let $p=1571$, set $x_0=Z$, and for $k\ge0$ let $x_{k+1}$ be the least nonnegative residue modulo $p$ of $x_k^2+789x_k+403$. Find the least nonnegative residue modulo $1000$ of $x_{10^{12}+10Z+81}+7\displaystyle\sum_{j=0}^{Z+28}x_j$.

Answer: 276


Let $Z$ be the least nonnegative residue modulo $1000$ of the number of permutations $\pi$ of $\{1,2,\ldots,9\}$ that have exactly $3$ cycles in their disjoint-cycle decomposition, exactly $2$ excedances, exactly $1$ fixed points, and major index congruent to $6$ modulo $7$. Put $L=18+(Z\bmod 13)$ and, for $1\le j\le L$, put $a_j=1+((Zj^2+15j+0)\bmod 15)$. If $[a_1;a_2,\ldots,a_L]=p_L/q_L$ and $p_{L-1}/q_{L-1}=[a_1;\ldots,a_{L-1}]$ are in lowest terms, find the least nonnegative residue modulo $1000$ of $p_L+q_L+5p_{L-1}+11q_{L-1}$.

Answer: 743


Triangle $ABC$ has side lengths $BC=17$, $CA=12$, and $AB=26$. An interior point $P$ has barycentric coordinates $(6:8:7)$, and $Q$ is the isotomic conjugate of $P$. The perpendiculars from $Q$ to $BC,CA,AB$ meet those lines at $D,E,F$, respectively. If $([DEF]/[ABC])^2=p/q$ in lowest terms, let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Let $p=1297$, let $A$ and $B$ be the least nonnegative residues modulo $p$ of $354Z+733$ and $440Z+973$, respectively, and consider $E: y^2=x^3+Ax+B$ over $\mathbb F_p$. Including the point at infinity, let $C=\#E(\mathbb F_p)$, and let $X$ be the sum, as ordinary integers, of the $x$-coordinates of all affine points of $E$. Find the least nonnegative residue of $C+5X$ modulo $1000$.

Answer: 687


A partition of $\{1,2,\ldots,9\}$ has a crossing quadruple when $a<b<c<d$, the numbers $a,c$ lie in one block, and $b,d$ lie in a different block. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of set partitions that have exactly $6$ blocks, exactly $5$ singleton blocks, and a number of crossing quadruples congruent to $0$ modulo $5$. Let $n=7+(Z\bmod 4)$ and let $M=(m_{ij})_{0\le i,j<n}$, where $m_{ij}$ is the least nonnegative residue modulo $19$ of $i^2+5ij+j^2+13Z(i+j+1)+14Z+6\,[i-j\equiv1\pmod n]$. Here the bracket equals $1$ when its condition holds and $0$ otherwise. Find the least nonnegative residue of $\det M$ modulo $1000$.

Answer: 508


In triangle $ABC$, the side lengths opposite $A,B,C$ are $33,33,13$, respectively. An interior point $P$ has barycentric coordinates $(5:4:3)$, and $Q$ is the isogonal conjugate of $P$. If $PQ^2=p/q$ in lowest terms, let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Let $A=\begin{pmatrix}3 & 4 & 1 & 4\\2 & 3 & 2 & 2\\2 & 2 & 0 & 2\\3 & 3 & 2 & 3\end{pmatrix}$. Interpreting powers over the integers and reducing only the final result, find the least nonnegative residue modulo $1000$ of $\operatorname{tr}(A^{Z+49})+11(A^{Z^2+38})_{1,4}$.

Answer: 295


For a positive integer $t$, let $J_2(t)=t^2\prod_{p\mid t}(1-p^{-2})$. Let $N=2012472$. Let $Z$ be the least nonnegative residue modulo $997$ of $\displaystyle\sum (d+1)J_2(N/d)$, where the sum is over squarefree divisors $d$ of $N$ such that $d\equiv 6\pmod{13}$ and $\Omega(d)\equiv 0\pmod2$. Let $A=\begin{pmatrix}0 & 0 & 4 & 4\\0 & 1 & 2 & 1\\2 & 1 & 1 & 1\\2 & 3 & 3 & 0\end{pmatrix}$. Interpreting powers over the integers and reducing only the final result, find the least nonnegative residue modulo $1000$ of $\operatorname{tr}(A^{Z+33})+5(A^{Z^2+41})_{1,4}$.

Answer: 334


Let $a_n$ be defined by $\displaystyle\sum_{n\ge0}a_nx^n=\frac{(1+x^8)^{5}(1+x^7+x^{14})^{5}}{(1-x^2)^{3}(1-x^5)^{2}}$. Let $Z$ be the least nonnegative residue modulo $983$ of $\displaystyle\sum_{\substack{0\le n\le 116\n\equiv 6\pmod{9}}}a_n$. Let $n=7+(Z\bmod 4)$ and let $M=(m_{ij})_{0\le i,j<n}$, where $m_{ij}$ is the least nonnegative residue modulo $29$ of $i^2+14ij+j^2+14Z(i+j+1)+4Z+5\,[i-j\equiv1\pmod n]$. Here the bracket equals $1$ when its condition holds and $0$ otherwise. Find the least nonnegative residue of $\det M$ modulo $1000$.

Answer: 720


The graph $C_5\square P_15$ has $15$ cyclic rows of $5$ vertices; adjacent vertices in each row are joined, including the wraparound pair, and corresponding vertices in consecutive rows are joined. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of independent sets that contain exactly $5$ vertices and leave a number of rows empty that is congruent to $0$ modulo $3$. Define $u_0=248$ and $u_1=999$, and for $k\ge 0$ define $u_{k+2}$ by $u_{k+2}\equiv 23u_{k+1}-7u_k-5(-1)^k\pmod{1000}$, with every $u_k$ chosen from $\{0,1,\ldots,999\}$. Find the least nonnegative residue modulo $1000$ of $u_{Z^2+5Z+28}+3u_{2Z+32}$.

Answer: 36


A tetrahedron $ABCD$ has squared edge lengths $AB^2=36$, $AC^2=128$, $AD^2=54$, $BC^2=68$, $BD^2=102$, and $CD^2=230$. Let $V$ be its volume and $R$ its circumradius. Write $R^2=p/q$ in lowest terms. Let $Z$ be the least nonnegative residue modulo $1000$ of $288V^2+p+q$. Let $R$ be the least nonnegative residue modulo $10^{10}-1$ of $7^{Z^2+6Z+79}+31^{Z+79}+8937579493$, and write $R$ as a block of exactly ten decimal digits, allowing leading zeros. For $0\le j<10$, let $R_j$ be the integer obtained by cyclically shifting this block left by $j$ places. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum (j+1)\gcd(R_j,10^{10}-1)$, where the sum is over the integers $j$ with $0\le j<10$ and $R_j\equiv 1\pmod{17}$.

Answer: 30


Let $p=5843$. A number $g$ with $1<g<p$ is called admissible when it is a primitive root modulo $p$, the sum of its base-$5$ digits is congruent to $4$ modulo $10$, and the sum of the base-$5$ digits of its least positive inverse modulo $p$ is congruent to $5$ modulo $7$. Let $Z$ be the least nonnegative residue modulo $1000$ of the sum of all admissible $g$. Let $m=8+(Z\bmod 9)$. Form a wheel with hub $0$ and rim vertices $1,2,\ldots,m$ in cyclic order. Give spoke $0j$ weight $1+((Z+j^2+j)\bmod5)$ and rim edge $j(j+1)$ weight $1+((2Z+2j+j^2)\bmod5)$, with $m+1$ interpreted as $1$. The weight of a spanning tree is the product of its edge weights. Find the total weight of all spanning trees modulo $1000$.

Answer: 320


A tetrahedron $ABCD$ has squared edge lengths $AB^2=49$, $AC^2=208$, $AD^2=116$, $BC^2=145$, $BD^2=109$, and $CD^2=68$. Let $V$ be its volume and $R$ its circumradius. Write $R^2=p/q$ in lowest terms. Let $Z$ be the least nonnegative residue modulo $1000$ of $288V^2+p+q$. Define $u_0=616$ and $u_1=471$, and for $k\ge 0$ define $u_{k+2}$ by $u_{k+2}\equiv 17u_{k+1}+9u_k+7(-1)^k\pmod{1000}$, with every $u_k$ chosen from $\{0,1,\ldots,999\}$. Find the least nonnegative residue modulo $1000$ of $u_{Z^2+5Z+69}+13u_{2Z+27}$.

Answer: 536


Let $r_1,r_2,r_3,r_4$ be the complex roots, counted with multiplicity, of $P(x)=x^{4} + x^{3} + x^{2} - 3 x + 3$. For the six numbers $s_{ij}=r_i+r_j$ with $1\le i<j\le4$, set $T=\displaystyle\sum_{i<j}\left(\frac{1}{(11-s_{ij})^2}+4\frac{1}{11-s_{ij}}\right)$. If $T=\frac pq$ in lowest terms with $q>0$, let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Define $P(x)=x^{5} - 4 x^{4} + 457 x^{3} + 6 x^{2} - x - 3$ and $Q(x)=x^{4} + 2 x^{3} + 917 x^{2} + 2 x - 8$. Find the least nonnegative residue modulo $1000$ of the resultant $\operatorname{Res}_x(P,Q)$.

Answer: 234


For $0\le i,j\le5$, define $m_{ij}=\binom{37+i+j}{20+2i-j}+4\binom{37+i+j}{20-i+2j}+2\binom{37+i+j}{20+i-j-2}$, where a binomial coefficient is $0$ when its lower index is outside its usual range. If $M=(m_{ij})_{0\le i,j\le5}$, let $Z$ be the least nonnegative residue of $\det M$ modulo $991$. Write $Z=100d_2+10d_1+d_0$ with $0\le d_0,d_1,d_2\le9$. Let $\lambda=(16+d_2+d_1+d_0,12+d_1+d_0,8+d_0,4,2)$. Find the least nonnegative residue modulo $1000$ of the number of standard Young tableaux of shape $\lambda$.

Answer: 0


Let $p=1579$. A number $g$ with $1<g<p$ is called admissible when it is a primitive root modulo $p$, the sum of its base-$11$ digits is congruent to $6$ modulo $11$, and the sum of the base-$11$ digits of its least positive inverse modulo $p$ is congruent to $3$ modulo $6$. Let $Z$ be the least nonnegative residue modulo $1000$ of the sum of all admissible $g$. Write $Z=100d_2+10d_1+d_0$ with $0\le d_0,d_1,d_2\le9$. Let $\lambda=(15+d_2+d_1+d_0,11+d_1+d_0,7+d_0,4,2)$. Find the least nonnegative residue modulo $1000$ of the number of standard Young tableaux of shape $\lambda$.

Answer: 0


The sequence $(a_n)$ is defined by $(a_0,a_1,\ldots,a_5)=(-3, 14, -17, -17, 3, 13)$ and $a_{n+6}=8a_{n+5}-5a_{n+4}+2a_{n+2}+7a_{n+1}+a_n$ for $n\ge0$. Let $M$ be the $5\times5$ matrix whose $(i,j)$ entry is $a_{3800044329232+i+j}-3a_{3800044329232+i+j+1}$, where $0\le i,j\le4$. Let $Z$ be the least nonnegative residue of $\det(M)$ modulo $997$. Define $P(x)=x^{5} + 5 x^{4} + 785 x^{3} + 3 x^{2} + x + 2$ and $Q(x)=x^{4} - 8 x^{3} + 1586 x^{2} - 3 x + 21$. Find the least nonnegative residue modulo $1000$ of the resultant $\operatorname{Res}_x(P,Q)$.

Answer: 573


Let $Z$ be the least nonnegative residue modulo $1000$ of the number of length-$42$ words $a_1a_2\cdots a_42$ over $\{0,1,2,3\}$ that contain none of the blocks $00$, $123$, or $232$, contain exactly $38$ occurrences of $3$, satisfy $\sum_{i=1}^42 i a_i\equiv 3\pmod7$, and have a number of indices with $a_{i+1}>a_i$ congruent to $1$ modulo $3$. Let $m=8+(Z\bmod 9)$. Form a wheel with hub $0$ and rim vertices $1,2,\ldots,m$ in cyclic order. Give spoke $0j$ weight $1+((Z+j^2+j)\bmod5)$ and rim edge $j(j+1)$ weight $1+((2Z+7j+j^2)\bmod5)$, with $m+1$ interpreted as $1$. The weight of a spanning tree is the product of its edge weights. Find the total weight of all spanning trees modulo $1000$.

Answer: 133


Consider ordered pairs $(x,y)$ of least positive residues modulo $12960$ satisfying $xy\equiv 5729\pmod{12960}$, $x+y\equiv 6\pmod{8}$, and $x+2y\equiv 2\pmod{9}$. Let $Z$ be the least nonnegative residue modulo $1000$ of $\displaystyle\sum(x+3y)$ over all such pairs. Put $L=18+(Z\bmod 13)$ and, for $1\le j\le L$, put $a_j=1+((Zj^2+4j+9)\bmod 11)$. If $[a_1;a_2,\ldots,a_L]=p_L/q_L$ and $p_{L-1}/q_{L-1}=[a_1;\ldots,a_{L-1}]$ are in lowest terms, find the least nonnegative residue modulo $1000$ of $p_L+q_L+3p_{L-1}+11q_{L-1}$.

Answer: 534


The sequence $(a_n)$ is defined by $(a_0,a_1,\ldots,a_5)=(16, -18, 18, -17, -16, 16)$ and $a_{n+6}=-8a_{n+5}+4a_{n+2}-7a_{n+1}-a_n$ for $n\ge0$. Let $M$ be the $5\times5$ matrix whose $(i,j)$ entry is $a_{917841055891+i+j}-4a_{917841055891+i+j+1}$, where $0\le i,j\le4$. Let $Z$ be the least nonnegative residue of $\det(M)$ modulo $997$. Put $L=Z+39$. For an integer $q\ge2$, let $P_q(L)$ be the number of rotation classes of aperiodic length-$L$ words over a $q$-letter alphabet. Find the least nonnegative residue modulo $1000$ of $P_6(L)+3P_5(L)+\varphi(L)$, where here $q=6$.

Answer: 910


Let $N=1440$. Consider nondecreasing $4$-tuples of integers $2\le a_1\le\cdots\le a_4$ whose product is $N$. Among those having exactly $2$ even entries, greatest common divisor $1$, and $a_1+\cdots+a_4\equiv 7\pmod{9}$, let $Z$ be the least nonnegative residue modulo $1000$ of the sum of all possible values of $a_4$. In the quotient ring $(\mathbb Z/1000\mathbb Z)[x]/(x^{5}+5x^{4}-2x^{3}-6x^{2}-4x+4)$, write $(x^{3}+3x^{2}+x+5)^{Z^2+8Z+63}=r_0+r_1x+r_2x^2+r_3x^3+r_4x^4$. Find the least nonnegative residue modulo $1000$ of $4r_0+2r_1-7r_2-5r_3-3r_4$.

Answer: 228


Let $C_{243}=\frac1{244}\binom{486}{243}$ be a Catalan number. Write $C_{243}=11^e u$ with $11\nmid u$. Let $Z$ be the least nonnegative residue of $u+67e$ modulo $1000$. Let $M=3080$ and let $R$ be the least nonnegative residue modulo $M$ of $(10Z+239)^2+1(10Z+239)$. Let $\mathcal S$ be the set of residues $z\in\{0,1,\ldots,M-1\}$ satisfying $z^2+1z\equiv R\pmod M$, $z\equiv 4\pmod{12}$, and $s_7(z)\equiv 4\pmod{6}$, where $s_7$ is the base-7 digit sum. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum_{z\in\mathcal S}((z+1)^2+3z)$.

Answer: 236


Let $p=4597$. A number $g$ with $1<g<p$ is called admissible when it is a primitive root modulo $p$, the sum of its base-$8$ digits is congruent to $1$ modulo $5$, and the sum of the base-$8$ digits of its least positive inverse modulo $p$ is congruent to $0$ modulo $10$. Let $Z$ be the least nonnegative residue modulo $1000$ of the sum of all admissible $g$. Let $R$ be the least nonnegative residue modulo $10^{10}-1$ of $11^{Z^2+5Z+50}+41^{Z+50}+2268065337$, and write $R$ as a block of exactly ten decimal digits, allowing leading zeros. For $0\le j<10$, let $R_j$ be the integer obtained by cyclically shifting this block left by $j$ places. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum (j+1)\gcd(R_j,10^{10}-1)$, where the sum is over the integers $j$ with $0\le j<10$ and $R_j\equiv 9\pmod{11}$.

Answer: 30


In triangle $ABC$ with $BC=36$, $CA=36$, and $AB=31$, points $D,E,F$ lie on $BC,CA,AB$, respectively, and satisfy $BD:DC=2:4$, $CE:EA=1:5$, and $AF:FB=3:3$. The circles $(ADE)$, $(BEF)$, and $(CFD)$ have radical center $X$. If the power of $X$ with respect to the circumcircle of $ABC$ is $p_0/q_0$ in lowest terms with $q_0>0$, let $Z$ be the least nonnegative residue of $p_0+q_0$ modulo $1000$. Define $u_0=71$ and $u_1=384$, and for $k\ge 0$ define $u_{k+2}$ by $u_{k+2}\equiv 13u_{k+1}-7u_k-13(-1)^k\pmod{1000}$, with every $u_k$ chosen from $\{0,1,\ldots,999\}$. Find the least nonnegative residue modulo $1000$ of $u_{Z^2+8Z+21}+13u_{2Z+21}$.

Answer: 590


For a positive integer $t$, let $J_2(t)=t^2\prod_{p\mid t}(1-p^{-2})$. Let $N=26583700$. Let $Z$ be the least nonnegative residue modulo $997$ of $\displaystyle\sum (d+1)J_2(N/d)$, where the sum is over squarefree divisors $d$ of $N$ such that $d\equiv 0\pmod{10}$ and $\Omega(d)\equiv 1\pmod2$. Write $Z=100d_2+10d_1+d_0$ with $0\le d_0,d_1,d_2\le9$. Let $\lambda=(17+d_2+d_1+d_0,13+d_1+d_0,9+d_0,4,2)$. Find the least nonnegative residue modulo $1000$ of the number of standard Young tableaux of shape $\lambda$.

Answer: 320


Let $C_{684}=\frac1{685}\binom{1368}{684}$ be a Catalan number. Write $C_{684}=7^e u$ with $7\nmid u$. Let $Z$ be the least nonnegative residue of $u+70e$ modulo $1000$. Let $p=1657$, set $x_0=Z$, and for $k\ge0$ let $x_{k+1}$ be the least nonnegative residue modulo $p$ of $x_k^2+939x_k+445$. Find the least nonnegative residue modulo $1000$ of $x_{10^{12}+8Z+50}+3\displaystyle\sum_{j=0}^{Z+50}x_j$.

Answer: 555


Two walkers move simultaneously on the lattice, each taking one unit north or east step per second. The lower walker goes from $(0,0)$ to $(9,12)$, and the upper walker goes from $(0,2)$ to $(9,14)$. After every equal number of steps, their current vertices must be distinct. A turn is a change of direction by either walker. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of ordered pairs of walks of such paths that have exactly $24$ turns in total and have the lower path visit exactly $3$ vertices on the line $y=x$, counting its initial vertex. Put $L=Z+62$. Let $S(n,k)$ be a Stirling number of the second kind, and let $A(n,j)$ be the number of permutations of $\{1,\ldots,n\}$ with exactly $j$ descents. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum_{j=0}^{7}(j+1)S(L+j,8)A(L,j)5^j$.

Answer: 920


Let $p=2393$. A number $g$ with $1<g<p$ is called admissible when it is a primitive root modulo $p$, the sum of its base-$7$ digits is congruent to $1$ modulo $9$, and the sum of the base-$7$ digits of its least positive inverse modulo $p$ is congruent to $4$ modulo $6$. Let $Z$ be the least nonnegative residue modulo $1000$ of the sum of all admissible $g$. Put $H=Z+69$. Find the least nonnegative residue modulo $1000$ of the number of ordered pairs $(a,b)$ that satisfy $1\le a<b\le H$, $\gcd(a,b)=1$, $a+b\equiv 7\pmod{8}$, and $\left\lfloor Ha/b\right\rfloor\equiv 2\pmod{5}$.

Answer: 150


Let $C_{823}=\frac1{824}\binom{1646}{823}$ be a Catalan number. Write $C_{823}=3^e u$ with $3\nmid u$. Let $Z$ be the least nonnegative residue of $u+66e$ modulo $1000$. Put $H=Z+100$. Find the least nonnegative residue modulo $1000$ of the number of ordered pairs $(a,b)$ that satisfy $1\le a<b\le H$, $\gcd(a,b)=1$, $a+b\equiv 8\pmod{11}$, and $\left\lfloor Ha/b\right\rfloor\equiv 4\pmod{6}$.

Answer: 46


For a positive integer $t$, let $J_2(t)=t^2\prod_{p\mid t}(1-p^{-2})$. Let $N=242219250$. Let $Z$ be the least nonnegative residue modulo $997$ of $\displaystyle\sum (d+1)J_2(N/d)$, where the sum is over squarefree divisors $d$ of $N$ such that $d\equiv 0\pmod{13}$ and $\Omega(d)\equiv 0\pmod2$. Put $L=Z+42$. For an integer $q\ge2$, let $P_q(L)$ be the number of rotation classes of aperiodic length-$L$ words over a $q$-letter alphabet. Find the least nonnegative residue modulo $1000$ of $P_7(L)+5P_6(L)+\varphi(L)$, where here $q=7$.

Answer: 254


Consider ordered pairs $(x,y)$ of least positive residues modulo $21600$ satisfying $xy\equiv 20813\pmod{21600}$, $x+y\equiv 4\pmod{10}$, and $x+2y\equiv 7\pmod{9}$. Let $Z$ be the least nonnegative residue modulo $1000$ of $\displaystyle\sum(x+3y)$ over all such pairs. In the quotient ring $(\mathbb Z/1000\mathbb Z)[x]/(x^{5}-5x^{4}-5x^{3}+3x^{2}-4x-2)$, write $(-x^{3}-2x^{2}-x+4)^{Z^2+5Z+72}=r_0+r_1x+r_2x^2+r_3x^3+r_4x^4$. Find the least nonnegative residue modulo $1000$ of $-7r_0-7r_1-5r_2-3r_3-3r_4$.

Answer: 728


For $1\le k<1680$ with $\gcd(k,1680)=1$ and $k\equiv 5\pmod{7}$, define $w_k=\gcd(k^2+5k+12,1680)\gcd(k^3+6,1680)$. Let $Z$ be the least nonnegative residue of $\sum w_k$ modulo $1000$. Let $R$ be the least nonnegative residue modulo $10^{10}-1$ of $23^{Z^2+9Z+56}+41^{Z+56}+5823509168$, and write $R$ as a block of exactly ten decimal digits, allowing leading zeros. For $0\le j<10$, let $R_j$ be the integer obtained by cyclically shifting this block left by $j$ places. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum (j+1)\gcd(R_j,10^{10}-1)$, where the sum is over the integers $j$ with $0\le j<10$ and $R_j\equiv 5\pmod{13}$.

Answer: 1


Let $E$ be the exponent of the prime $17$ in the integer $\displaystyle\prod_{k=1}^{120725}(6^k-1)^{\lfloor 120725/k\rfloor+\lfloor k/12\rfloor}$. Let $Z$ be the least nonnegative residue of $E$ modulo $1000$. Define $u_0=996$ and $u_1=576$, and for $k\ge 0$ define $u_{k+2}$ by $u_{k+2}\equiv 11u_{k+1}+14u_k-19(-1)^k\pmod{1000}$, with every $u_k$ chosen from $\{0,1,\ldots,999\}$. Find the least nonnegative residue modulo $1000$ of $u_{Z^2+10Z+39}+13u_{2Z+45}$.

Answer: 243


Let $\theta_k=\frac{2\pi k}{11}$ for $1\le k\le 10$. If $\displaystyle\sum_{k=1}^{10}\left(\frac1{(10-2\cos\theta_k)^2}+\frac{6}{10-2\cos\theta_k}\right)=\frac pq$ in lowest terms, let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Let $p=2179$, let $A$ and $B$ be the least nonnegative residues modulo $p$ of $1552Z+1051$ and $112Z+1558$, respectively, and consider $E: y^2=x^3+Ax+B$ over $\mathbb F_p$. Including the point at infinity, let $C=\#E(\mathbb F_p)$, and let $X$ be the sum, as ordinary integers, of the $x$-coordinates of all affine points of $E$. Find the least nonnegative residue of $C+2X$ modulo $1000$.

Answer: 513


A partition of $\{1,2,\ldots,10\}$ has a crossing quadruple when $a<b<c<d$, the numbers $a,c$ lie in one block, and $b,d$ lie in a different block. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of set partitions that have exactly $5$ blocks, exactly $2$ singleton blocks, and a number of crossing quadruples congruent to $0$ modulo $5$. Put $L=Z+59$. Define $G(n,0)=1$, $G(0,k)=0$ for $k>0$, and $G(n,k)=G(n-1,k)+5^{n-k}G(n-1,k-1)$. Find the least nonnegative residue modulo $1000$ of $G(L,7)+2G(L,6)$.

Answer: 793


Let $N=15211$. Consider triples of positive integers $x\le y\le z$ satisfying $x^2+y^2+z^2=N$ and $\gcd(x,y,z)=1$. Among those with $x+y+z\equiv 5\pmod{8}$, let $Z$ be the least nonnegative residue modulo $1000$ of $\displaystyle\sum(x+2y+3z)$. Set $T=7^{Z+1}+\displaystyle\sum_{k=0}^Z(-1)^k\binom Zk7^k5^{Z-k}(k^3+7k^2-8k-17)$. Find the least nonnegative residue of $T$ modulo $1000$.

Answer: 711


A polynomial $F$ of degree at most $9$ has remainder $1958 + 9901(x-2) + 22240(x-2)^{2} + 28856(x-2)^{3}$ upon division by $(x-2)^4$, remainder $-4622 + 21037(x+2) - 42336(x+2)^{2}$ upon division by $(x+2)^3$, and remainder $-2365048 + 5287741(x+4) - 5245496(x+4)^{2}$ upon division by $(x+4)^3$. Let $Z$ be the least nonnegative residue of $F(-7)$ modulo $1000$. Let $L=Z+31$ and $P=\displaystyle\prod_{j=1}^L(4j+4)$. Write $P=5^eU$ with $5\nmid U$, and let $u$ be the least nonnegative residue of $U$ modulo $5^4=625$. Find the least nonnegative residue modulo $1000$ of $u+13e+2(e\bmod 4)^2$.

Answer: 398


Let $a_n$ be defined by $\displaystyle\sum_{n\ge0}a_nx^n=\frac{(1+x^3)^{3}(1+x^7+x^{14})^{2}}{(1-x^5)^{2}(1-x^4)^{4}}$. Let $Z$ be the least nonnegative residue modulo $997$ of $\displaystyle\sum_{\substack{0\le n\le 116\n\equiv 4\pmod{9}}}a_n$. Put $L=Z+74$. For an integer $q\ge2$, let $P_q(L)$ be the number of rotation classes of aperiodic length-$L$ words over a $q$-letter alphabet. Find the least nonnegative residue modulo $1000$ of $P_8(L)+2P_7(L)+\varphi(L)$, where here $q=8$.

Answer: 904


For a positive integer $t$, let $J_2(t)=t^2\prod_{p\mid t}(1-p^{-2})$. Let $N=50611275$. Let $Z$ be the least nonnegative residue modulo $997$ of $\displaystyle\sum (d+1)J_2(N/d)$, where the sum is over squarefree divisors $d$ of $N$ such that $d\equiv 4\pmod{7}$ and $\Omega(d)\equiv 1\pmod2$. Define $u_0=473$ and $u_1=160$, and for $k\ge 0$ define $u_{k+2}$ by $u_{k+2}\equiv 11u_{k+1}+5u_k+7(-1)^k\pmod{1000}$, with every $u_k$ chosen from $\{0,1,\ldots,999\}$. Find the least nonnegative residue modulo $1000$ of $u_{Z^2+9Z+82}+7u_{2Z+34}$.

Answer: 636


Two walkers move simultaneously on the lattice, each taking one unit north or east step per second. The lower walker goes from $(0,0)$ to $(8,7)$, and the upper walker goes from $(0,2)$ to $(8,9)$. After every equal number of steps, their current vertices must be distinct. A turn is a change of direction by either walker. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of ordered pairs of walks of such paths that have exactly $10$ turns in total and have the lower path visit exactly $5$ vertices on the line $y=x$, counting its initial vertex. Let $A=\begin{pmatrix}4 & 0 & 1 & 3\\2 & 4 & 4 & 3\\0 & 3 & 3 & 1\\1 & 2 & 4 & 4\end{pmatrix}$. Interpreting powers over the integers and reducing only the final result, find the least nonnegative residue modulo $1000$ of $\operatorname{tr}(A^{Z+17})+2(A^{Z^2+70})_{1,4}$.

Answer: 130


The eight vertices of a cube are colored red, green, or blue, using the colors exactly $3, 2, 3$ times, respectively. Two colorings are considered the same when a rotation of the cube carries one to the other. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of equivalence classes that have exactly $5$ edges whose endpoints have the same color. Put $L=Z+23$. Let $S(n,k)$ be a Stirling number of the second kind, and let $A(n,j)$ be the number of permutations of $\{1,\ldots,n\}$ with exactly $j$ descents. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum_{j=0}^{7}(j+1)S(L+j,8)A(L,j)7^j$.

Answer: 406


The eight vertices of a cube are colored red, green, or blue, using the colors exactly $4, 3, 1$ times, respectively. Two colorings are considered the same when a rotation of the cube carries one to the other. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of equivalence classes that have exactly $3$ edges whose endpoints have the same color. Let $R$ be the least nonnegative residue modulo $10^{10}-1$ of $19^{Z^2+5Z+52}+29^{Z+52}+3143072797$, and write $R$ as a block of exactly ten decimal digits, allowing leading zeros. For $0\le j<10$, let $R_j$ be the integer obtained by cyclically shifting this block left by $j$ places. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum (j+1)\gcd(R_j,10^{10}-1)$, where the sum is over the integers $j$ with $0\le j<10$ and $R_j\equiv 2\pmod{13}$.

Answer: 75


Let $\theta_k=\frac{2\pi k}{23}$ for $1\le k\le 22$. If $\displaystyle\sum_{k=1}^{22}\left(\frac1{(3-2\cos\theta_k)^2}+\frac{5}{3-2\cos\theta_k}\right)=\frac pq$ in lowest terms, let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. In the quotient ring $(\mathbb Z/1000\mathbb Z)[x]/(x^{5}+6x^{4}-6x^{3}-3x^{2}+3x+2)$, write $(-5x^{4}-2x^{3}-3x^{2}+2x-2)^{Z^2+6Z+118}=r_0+r_1x+r_2x^2+r_3x^3+r_4x^4$. Find the least nonnegative residue modulo $1000$ of $-3r_0+4r_1+6r_2+9r_3+2r_4$.

Answer: 814


The sequence $(a_n)$ is defined by $(a_0,a_1,\ldots,a_5)=(-10, -15, -7, -7, -6, -10)$ and $a_{n+6}=6a_{n+5}-3a_{n+4}-6a_{n+2}-6a_n$ for $n\ge0$. Let $M$ be the $5\times5$ matrix whose $(i,j)$ entry is $a_{1024512110523+i+j}-2a_{1024512110523+i+j+1}$, where $0\le i,j\le4$. Let $Z$ be the least nonnegative residue of $\det(M)$ modulo $997$. Put $H=Z+105$. Find the least nonnegative residue modulo $1000$ of the number of ordered pairs $(a,b)$ that satisfy $1\le a<b\le H$, $\gcd(a,b)=1$, $a+b\equiv 1\pmod{7}$, and $\left\lfloor Ha/b\right\rfloor\equiv 1\pmod{4}$.

Answer: 37


Triangle $ABC$ has side lengths $BC=12$, $CA=25$, and $AB=22$. An interior point $P$ has barycentric coordinates $(5:5:1)$, and $Q$ is the isotomic conjugate of $P$. The perpendiculars from $Q$ to $BC,CA,AB$ meet those lines at $D,E,F$, respectively. If $([DEF]/[ABC])^2=p/q$ in lowest terms, let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Let $R$ be the least nonnegative residue modulo $10^{10}-1$ of $19^{Z^2+10Z+60}+29^{Z+60}+7821323505$, and write $R$ as a block of exactly ten decimal digits, allowing leading zeros. For $0\le j<10$, let $R_j$ be the integer obtained by cyclically shifting this block left by $j$ places. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum (j+1)\gcd(R_j,10^{10}-1)$, where the sum is over the integers $j$ with $0\le j<10$ and $R_j\equiv 1\pmod{7}$.

Answer: 330


A simple graph on $6$ labeled vertices is chosen uniformly from all connected such graphs. The probability that it has exactly $2$ vertices of odd degree and exactly $8$ triangles is $p/q$ in lowest terms. Let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Let $A=\begin{pmatrix}0 & 0 & 2 & 0\\2 & 3 & 2 & 3\\1 & 4 & 1 & 3\\4 & 2 & 1 & 1\end{pmatrix}$. Interpreting powers over the integers and reducing only the final result, find the least nonnegative residue modulo $1000$ of $\operatorname{tr}(A^{Z+20})+11(A^{Z^2+58})_{1,4}$.

Answer: 115


In triangle $ABC$ with $BC=33$, $CA=40$, and $AB=18$, points $D,E,F$ lie on $BC,CA,AB$, respectively, and satisfy $BD:DC=7:2$, $CE:EA=5:5$, and $AF:FB=2:2$. The circles $(ADE)$, $(BEF)$, and $(CFD)$ have radical center $X$. If the power of $X$ with respect to the circumcircle of $ABC$ is $p_0/q_0$ in lowest terms with $q_0>0$, let $Z$ be the least nonnegative residue of $p_0+q_0$ modulo $1000$. A Markov chain has transition matrix $\frac1{12}\begin{pmatrix}1 & 9 & 1 & 1\\5 & 2 & 4 & 1\\2 & 2 & 3 & 5\\3 & 6 & 1 & 2\end{pmatrix}$. It starts in state $4$. After $Z+88$ steps, the probability that it is in one of the states $\{3,4\}$ is $p/q$ in lowest terms with $q>0$. Find the least nonnegative residue of $p+q$ modulo $1000$.

Answer: 385


A circular ladder has two disjoint $8$-cycles, with corresponding vertices joined by $8$ rungs. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of matchings that contain exactly $8$ edges, exactly $4$ rungs, and a number of edges from the first cycle congruent to $2$ modulo $3$. Put $L=18+(Z\bmod 13)$ and, for $1\le j\le L$, put $a_j=1+((Zj^2+2j+10)\bmod 15)$. If $[a_1;a_2,\ldots,a_L]=p_L/q_L$ and $p_{L-1}/q_{L-1}=[a_1;\ldots,a_{L-1}]$ are in lowest terms, find the least nonnegative residue modulo $1000$ of $p_L+q_L+5p_{L-1}+3q_{L-1}$.

Answer: 763


For $1\le k<5400$ with $\gcd(k,5400)=1$ and $k\equiv 6\pmod{7}$, define $w_k=\gcd(k^2+7k+14,5400)\gcd(k^3+5,5400)$. Let $Z$ be the least nonnegative residue of $\sum w_k$ modulo $1000$. Let $p=1489$, set $x_0=Z$, and for $k\ge0$ let $x_{k+1}$ be the least nonnegative residue modulo $p$ of $x_k^2+1400x_k+597$. Find the least nonnegative residue modulo $1000$ of $x_{10^{12}+9Z+78}+7\displaystyle\sum_{j=0}^{Z+35}x_j$.

Answer: 545


Let $N=378000$. Consider nondecreasing $4$-tuples of integers $2\le a_1\le\cdots\le a_4$ whose product is $N$. Among those having exactly $2$ even entries, greatest common divisor $1$, and $a_1+\cdots+a_4\equiv 4\pmod{12}$, let $Z$ be the least nonnegative residue modulo $1000$ of the sum of all possible values of $a_4$. A Markov chain has transition matrix $\frac1{12}\begin{pmatrix}1 & 1 & 7 & 3\\1 & 3 & 5 & 3\\3 & 2 & 6 & 1\\2 & 6 & 3 & 1\end{pmatrix}$. It starts in state $4$. After $Z+88$ steps, the probability that it is in one of the states $\{1,4\}$ is $p/q$ in lowest terms with $q>0$. Find the least nonnegative residue of $p+q$ modulo $1000$.

Answer: 511


Let $F(x)=P(x^2+2x+2)$, where $P(x)=x^{4} + 4 x^{3} - 4 x^{2} + x + 3$. The discriminant of $F$ is an integer $D$. Let $Z$ be the least nonnegative residue of $D$ modulo $983$. Put $L=Z+57$. Let $S(n,k)$ be a Stirling number of the second kind, and let $A(n,j)$ be the number of permutations of $\{1,\ldots,n\}$ with exactly $j$ descents. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum_{j=0}^{6}(j+1)S(L+j,7)A(L,j)3^j$.

Answer: 640


A sphere $\Sigma$ is orthogonal to four spheres having, respectively, center $(6,4,2)$ and squared radius $\frac{213}{2}$; center $(1,0,2)$ and squared radius $\frac{71}{2}$; center $(5,7,-6)$ and squared radius $\frac{239}{2}$; and center $(-3,-8,-6)$ and squared radius $\frac{87}{2}$. If the center of $\Sigma$ is $(h,k,\ell)$ and its squared radius is $\rho$, and $h^2+k^2+\ell^2+\rho=p/q$ in lowest terms, let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Define $u_0=445$ and $u_1=369$, and for $k\ge 0$ define $u_{k+2}$ by $u_{k+2}\equiv 19u_{k+1}+5u_k-19(-1)^k\pmod{1000}$, with every $u_k$ chosen from $\{0,1,\ldots,999\}$. Find the least nonnegative residue modulo $1000$ of $u_{Z^2+5Z+33}+13u_{2Z+34}$.

Answer: 588


Let $F(x)=P(x^2+3x+0)$, where $P(x)=x^{4} - 4 x^{3} - 2 x^{2} + 4 x - 1$. The discriminant of $F$ is an integer $D$. Let $Z$ be the least nonnegative residue of $D$ modulo $991$. Let $R$ be the least nonnegative residue modulo $10^{10}-1$ of $17^{Z^2+7Z+99}+41^{Z+99}+6210865758$, and write $R$ as a block of exactly ten decimal digits, allowing leading zeros. For $0\le j<10$, let $R_j$ be the integer obtained by cyclically shifting this block left by $j$ places. Find the least nonnegative residue modulo $1000$ of $\displaystyle\sum (j+1)\gcd(R_j,10^{10}-1)$, where the sum is over the integers $j$ with $0\le j<10$ and $R_j\equiv 10\pmod{13}$.

Answer: 36


A simple graph on $6$ labeled vertices is chosen uniformly from all connected such graphs. The probability that it has exactly $6$ vertices of odd degree and exactly $0$ triangles is $p/q$ in lowest terms. Let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Put $L=Z+27$. Define $G(n,0)=1$, $G(0,k)=0$ for $k>0$, and $G(n,k)=G(n-1,k)+4^{n-k}G(n-1,k-1)$. Find the least nonnegative residue modulo $1000$ of $G(L,12)+7G(L,11)$.

Answer: 328


Two walkers move simultaneously on the lattice, each taking one unit north or east step per second. The lower walker goes from $(0,0)$ to $(10,7)$, and the upper walker goes from $(0,2)$ to $(10,9)$. After every equal number of steps, their current vertices must be distinct. A turn is a change of direction by either walker. Let $Z$ be the least nonnegative residue modulo $1000$ of the number of ordered pairs of walks of such paths that have exactly $12$ turns in total and have the lower path visit exactly $6$ vertices on the line $y=x$, counting its initial vertex. Put $H=Z+85$. Find the least nonnegative residue modulo $1000$ of the number of ordered pairs $(a,b)$ that satisfy $1\le a<b\le H$, $\gcd(a,b)=1$, $a+b\equiv 0\pmod{10}$, and $\left\lfloor Ha/b\right\rfloor\equiv 4\pmod{6}$.

Answer: 268


For $1\le k<8400$ with $\gcd(k,8400)=1$ and $k\equiv 7\pmod{12}$, define $w_k=\gcd(k^2+9k+8,8400)\gcd(k^3+5,8400)$. Let $Z$ be the least nonnegative residue of $\sum w_k$ modulo $1000$. Put $H=Z+89$. Find the least nonnegative residue modulo $1000$ of the number of ordered pairs $(a,b)$ that satisfy $1\le a<b\le H$, $\gcd(a,b)=1$, $a+b\equiv 0\pmod{7}$, and $\left\lfloor Ha/b\right\rfloor\equiv 1\pmod{4}$.

Answer: 628


Let $r_1,r_2,r_3,r_4$ be the roots of $P(x)=x^{4} - 4 x^{3} - 3 x^{2} - 4 x - 5$. For each unordered pair $i<j$, put $t_{ij}=r_ir_j$. If $\displaystyle\sum_{i<j}\frac{7+t_{ij}}{(13-t_{ij})^2}=\frac pq$ in lowest terms, let $Z$ be the least nonnegative residue of $p+q$ modulo $1000$. Define $u_0=27$ and $u_1=888$, and for $k\ge 0$ define $u_{k+2}$ by $u_{k+2}\equiv 11u_{k+1}+21u_k-5(-1)^k\pmod{1000}$, with every $u_k$ chosen from $\{0,1,\ldots,999\}$. Find the least nonnegative residue modulo $1000$ of $u_{Z^2+3Z+49}+11u_{2Z+21}$.

Answer: 910