MathsReadCompetitive mathematics
Algorithmic puzzle · integer answereasy25 min

First zero in a coupled recurrence

Recursive Sequences

Define a_0=1, a_1=3, and a_n=(3*a_(n-1)+7*a_(n-2)) mod 1009 for n>=2. Find the smallest n>=2 for which a_n=0. If no such n<=100000 exists, submit -1.

Solve using mathematics, algorithms, or your own code offline. Submit only the final integer here—no program, expression, graph, or written proof.

Check your answer without signing in. Sign in to save your progress.

Accepted format: a whole number such as 42 or 123456789. No commas, formulas, or source code.

How to approach this problem

Search successive ordered pairs of recurrence residues. Do not stop merely because one nonzero residue repeats: the next value depends on the previous residue too.

Worked example with different values

For Fibonacci residues modulo 3, the pair (0,1) returns after eight updates. A repeated single 1 earlier does not establish the full cycle.

Apply the same reasoning to the challenge. This example is a separate practice problem.

Learn the technique: Number theory: divisors, gcd and modular arithmetic

Report a question or explanation issue

Back to problems →