All Euler problems
Project Euler

Fibonacci Entry Points

For a positive integer m, the Fibonacci entry point (or rank of apparition) alpha(m) is the smallest positive k such that m | F_k. Find sum_(m=1)^(10^5) alpha(m).

Source sync May 21, 2026
Problem #0955
Level Level 20
Solved By 612
Languages C++, Python
Answer 6795261671274
Length 309 words
number_theorysequencemodular_arithmetic

Problem Statement

This archive keeps the full statement, math, and original media on the page.

A sequence \((a_n)_{n \ge 0}\) starts with \(a_0 = 3\) and for each \(n \ge 0\),

Problem 955: Fibonacci Entry Points

Mathematical Analysis

Pisano Periods and Entry Points

The Fibonacci sequence modulo mm is periodic; its period π(m)\pi(m) is called the Pisano period. The entry point α(m)\alpha(m) is the position of the first zero in this periodic sequence.

Theorem (Divisibility Properties).

  1. α(m)\alpha(m) always exists and α(m)≤π(m)\alpha(m) \le \pi(m).
  2. Fn≡0(modm)F_n \equiv 0 \pmod{m} if and only if α(m)∣n\alpha(m) \mid n.
  3. α(m)∣π(m)\alpha(m) \mid \pi(m).

Proof of (2). Let α=α(m)\alpha = \alpha(m). If n=qαn = q\alpha, then by the matrix identity (Fn+1,Fn;Fn,Fn−1)=(F2,F1;F1,F0)n(F_{n+1}, F_n; F_n, F_{n-1}) = (F_2, F_1; F_1, F_0)^n, we have Fqα≡0(modm)F_{q\alpha} \equiv 0 \pmod{m} by induction on qq. Conversely, if Fn≡0F_n \equiv 0 and n=qα+rn = q\alpha + r with 0≤r<α0 \le r < \alpha, then using Fa+b=FaFb+1+Fa−1FbF_{a+b} = F_a F_{b+1} + F_{a-1} F_b, we can show Fr≡0(modm)F_r \equiv 0 \pmod{m}, contradicting minimality unless r=0r = 0. □\square

Entry Points for Prime Powers

Theorem (Wall, 1960). For an odd prime pp:

  • α(p)\alpha(p) divides p−1p - 1 if p≡±1(mod5)p \equiv \pm 1 \pmod{5} (i.e., (5p)=1\left(\frac{5}{p}\right) = 1).
  • α(p)\alpha(p) divides 2(p+1)2(p + 1) if p≡±2(mod5)p \equiv \pm 2 \pmod{5} (i.e., (5p)=−1\left(\frac{5}{p}\right) = -1).

Theorem (Prime Power Lifting). For prime pp and a≥1a \ge 1:

α(pa)=pa−1⋅α(p)\alpha(p^a) = p^{a-1} \cdot \alpha(p)

except possibly for Wall—Sun—Sun primes (none known as of 2025).

Entry Points for Composites

Theorem. For gcd⁡(a,b)=1\gcd(a, b) = 1:

α(ab)=lcm⁡(α(a),α(b))\alpha(ab) = \operatorname{lcm}(\alpha(a), \alpha(b))

Proof. ab∣Fkab \mid F_k iff both a∣Fka \mid F_k and b∣Fkb \mid F_k (by coprimality), iff α(a)∣k\alpha(a) \mid k and α(b)∣k\alpha(b) \mid k, iff lcm⁡(α(a),α(b))∣k\operatorname{lcm}(\alpha(a), \alpha(b)) \mid k. □\square

Concrete Examples

mmα(m)\alpha(m)First zero in Fk mod mF_k \bmod m
11F1=1≡0(mod1)F_1 = 1 \equiv 0 \pmod{1}
23F3=2F_3 = 2
34F4=3F_4 = 3
55F5=5F_5 = 5
78F8=21=3⋅7F_8 = 21 = 3 \cdot 7
1015F15=610=61⋅10F_{15} = 610 = 61 \cdot 10
1212lcm⁡(α(4),α(3))=lcm⁡(6,4)=12\operatorname{lcm}(\alpha(4), \alpha(3)) = \operatorname{lcm}(6, 4) = 12

Derivation

For each mm from 1 to 10510^5:

  1. Compute Fibonacci numbers modulo mm: F0=0,F1=1,Fk+1=Fk+Fk−1(modm)F_0 = 0, F_1 = 1, F_{k+1} = F_k + F_{k-1} \pmod{m}.
  2. Find the smallest k≥1k \ge 1 with Fk≡0(modm)F_k \equiv 0 \pmod{m}.
  3. This kk is α(m)\alpha(m).

The search terminates because the Pisano period exists, with π(m)≤6m\pi(m) \le 6m.

Optimization

For mm with known factorization m=p1a1⋯prarm = p_1^{a_1} \cdots p_r^{a_r}:

  • Compute α(pi)\alpha(p_i) for each prime factor.
  • Lift: α(piai)=piai−1α(pi)\alpha(p_i^{a_i}) = p_i^{a_i - 1} \alpha(p_i).
  • Combine: α(m)=lcm⁡(α(p1a1),…,α(prar))\alpha(m) = \operatorname{lcm}(\alpha(p_1^{a_1}), \ldots, \alpha(p_r^{a_r})).

This avoids searching up to 6m6m for large mm.

Proof of Correctness

The Fibonacci sequence modulo mm is deterministic and periodic (pigeonhole on pairs (Fk,Fk+1) mod m(F_k, F_{k+1}) \bmod m, with at most m2m^2 possible pairs). The first occurrence of Fk≡0F_k \equiv 0 is well-defined and equals α(m)\alpha(m).

Complexity Analysis

  • Direct search: O(m)O(m) per value, O(N⋅αˉ)O(N \cdot \bar{\alpha}) total, where αˉ≈N/3\bar{\alpha} \approx N/3 on average. Roughly O(N2)O(N^2).
  • Factorization-based: O(m)O(\sqrt{m}) per factorization + O(α(p))O(\alpha(p)) per prime, giving O(N3/2)O(N^{3/2}) total.
  • Space: O(1)O(1) per computation (only track current and previous Fibonacci terms).

Answer

6795261671274\boxed{6795261671274}

Code

Each problem page includes the exact C++ and Python source files from the local archive.

C++ project_euler/problem_955/solution.cpp
/*
 * Problem 955: Fibonacci Entry Points
 *
 * For each m = 1..10^5, find alpha(m) = smallest k >= 1 with m | F_k.
 * Return sum of all alpha(m).
 *
 * Direct search: iterate F_k mod m until F_k = 0.
 * Guaranteed to terminate: Pisano period pi(m) <= 6m.
 *
 * Complexity: O(N * avg_alpha) ~ O(N^2).
 */

#include <bits/stdc++.h>
using namespace std;

int fibonacci_entry_point(int m) {
    if (m == 1) return 1;
    int a = 0, b = 1;
    for (int k = 1; k <= 6 * m + 1; k++) {
        int c = (a + b) % m;
        a = b;
        b = c;
        if (a == 0) return k;
    }
    return -1;  // should not reach
}

int main() {
    const int N = 100000;
    long long total = 0;

    for (int m = 1; m <= N; m++) {
        total += fibonacci_entry_point(m);
    }

    cout << total << endl;
    return 0;
}