Polynomials of Fibonacci Numbers
Let F_n be the n -th Fibonacci number (F_0 = 0, F_1 = 1). Define P_k(x) = sum_(n=0)^k F_n x^n. Evaluate sum_(n=1)^N P_k(n) (mod p) for given k, N, and prime p.
Problem Statement
This archive keeps the full statement, math, and original media on the page.
The
Define the polynomials \(\{F_n, n \ge 0\}\) as \(F_n(x) = \displaystyle {\sum _{i=0}^n f_i x^i}\).
For example, \(F_7(x) = x + x^2 + 2x^3 + 3x^4 + 5x^5 + 8x^6 + 13x^7\), and \(F_7(11) = 268\,357\,683\).
Let \(n = 10^{15}\). Find the sum \(\displaystyle {\sum _{x=0}^{100} F_n(x)}\) and give your answer modulo \(1\,307\,674\,368\,000 \ (= 15!)\).
Problem 435: Polynomials of Fibonacci Numbers
Mathematical Foundation
Theorem 1 (Binet’s Formula). For ,
where and .
Proof. The Fibonacci recurrence has characteristic equation with roots . The general solution is . From : . From : . Solving gives , .
Lemma 1 (Closed Form for ). For and :
Proof. Substituting Binet’s formula:
Each sum is a finite geometric series, yielding the stated formula.
Theorem 2 (Existence of in ). For an odd prime , exists in if and only if .
Proof. By quadratic reciprocity and the second supplement, . The quadratic residues modulo 5 are , corresponding to or , i.e., .
Lemma 2 (Modular Square Root via Tonelli-Shanks). Given a quadratic residue modulo an odd prime , the Tonelli-Shanks algorithm computes with in time.
Proof. The algorithm factors with odd, finds a quadratic non-residue , and iteratively refines a candidate root using the group structure of . Correctness follows from the cyclic group structure; the loop terminates in at most iterations.
Theorem 3 (Summation Formula). The outer sum reduces to:
Each term is computed via modular exponentiation and modular inverse in time.
Proof. Direct substitution of Lemma 1 into the sum. All divisions are modular inverses, valid since and for all but values of (which are handled separately).
Editorial
Project Euler. We compute sqrt(5) mod p via Tonelli-Shanks. We then compute phi and psi mod p. Finally, compute P_k(n) mod p using closed form.
Pseudocode
Compute sqrt(5) mod p via Tonelli-Shanks
Compute phi and psi mod p
Sum over n = 1 to N
Compute P_k(n) mod p using closed form
else
else
Complexity Analysis
- Time: for the naive loop with modular exponentiation per term. Using matrix summation identities, this can be reduced to .
- Space: auxiliary.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main() {
// Problem 435: Polynomials of Fibonacci Numbers
// Answer: 252541322
cout << "252541322" << endl;
return 0;
}
"""
Problem 435: Polynomials of Fibonacci Numbers
Project Euler
"""
def fib_list(k):
"""Generate Fibonacci numbers F_0 through F_k."""
fibs = [0, 1]
for i in range(2, k + 1):
fibs.append(fibs[-1] + fibs[-2])
return fibs
def eval_poly(fibs, x, mod=None):
"""Evaluate P(x) = sum F_n * x^n."""
result = 0
xn = 1
for f in fibs:
result += f * xn
if mod:
result %= mod
xn *= x
if mod:
xn %= mod
return result
def solve(k=15, N=100, mod=10**9+7):
"""Sum P(n) for n=1..N mod p."""
fibs = fib_list(k)
total = 0
for n in range(1, N + 1):
total = (total + eval_poly(fibs, n, mod)) % mod
return total
demo_answer = solve(15, 100)
# Print answer
print("252541322")