Fibonacci residues that are squares
Recursive Sequences
Use F_0=0, F_1=1 and F_n=F_(n-1)+F_(n-2). For how many indices n with 1<=n<=1000000000000 is F_n modulo 997 a quadratic residue modulo 997? Include residue 0 as a square.
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.
How to approach this problem
Precompute residues that are squares by squaring every residue. Detect the Fibonacci cycle using consecutive pairs and count its qualifying positions; multiply by complete cycles and handle the remainder.
Worked example with different values
Squares modulo 5 are 0,1,4. For Fibonacci residues, 2 and 3 do not qualify, but a zero residue does.
Apply the same reasoning to the challenge. This example is a separate practice problem.
Learn the technique: Number theory: divisors, gcd and modular arithmetic