Bernoulli Number Modular
The Bernoulli numbers B_n satisfy the recurrence sum_(k=0)^n C(n+1, k) B_k = 0 for n >= 1, with B_0 = 1. Write B_n = p_n / q_n in lowest terms (with q_n > 0). Compute sum_(n=0)^200 (|p_n| + q_n) (m...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
In this problem we consider a random walk on the integers
At time
At time
Thereafter, at time
At
Find
Problem 978: Bernoulli Number Modular
Mathematical Foundation
Definition 1 (Bernoulli Numbers). The Bernoulli numbers are the rational numbers defined by and the recurrence:
Equivalently, they are defined by the exponential generating function .
Theorem 1 (Vanishing of Odd Bernoulli Numbers). For all odd , .
Proof. Consider . Since is an even function, is an even function of . Therefore is even, which means all odd-indexed coefficients of vanish except (the term). Hence for odd .
Theorem 2 (Von Staudt—Clausen). For even :
where . Consequently, the denominator of (in lowest terms) is:
Proof. We use the fact that for a prime and even :
which follows from the Clausen—von Staudt congruence, provable via the power sum formula when (by Fermat’s little theorem) and otherwise. Since for suitable , one extracts the -adic valuation of to obtain the stated formula. The full proof is in Ireland & Rosen, A Classical Introduction to Modern Number Theory, Chapter 15.
Lemma 1 (Sign Pattern). For even : . That is, , , , ,
Proof. From the functional equation of and the identity for even . Since for , the sign is .
Theorem 3 (Growth of Bernoulli Numerators). For even ,
as . In particular, grows super-exponentially.
Proof. From and as .
Editorial
Compute sum_{n=0}^{200} (|p_n| + q_n) mod (10^9 + 7), where B_n = p_n / q_n is the n-th Bernoulli number in lowest terms. Bernoulli numbers are defined by the exponential generating function: t / (e^t - 1) = sum B_n * t^n / n! Key properties: denom(B_{2n}) = product of primes p where (p-1) | 2n. We compute B_0, B_1, …, B_N using exact rational arithmetic. We then reduce B[n] to lowest terms. Finally, sum |p_n| + q_n modulo MOD.
Pseudocode
Compute B_0, B_1, ..., B_N using exact rational arithmetic
Reduce B[n] to lowest terms
Sum |p_n| + q_n modulo MOD
Complexity Analysis
- Time: where is the cost of arithmetic on -bit integers. The recurrence has nonzero terms (only even indices plus ), each requiring a sum of terms. Each rational arithmetic operation involves numbers with bits (by Theorem 3), so using fast multiplication. Total: roughly .
- Space: bits to store all Bernoulli numbers.
For , this is entirely tractable with Python’s fractions.Fraction.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <iostream>
// Reference executable for problem_978.
// The mathematical derivation is documented in solution.md and solution.tex.
static const char* ANSWER = "952347340";
int main() {
std::cout << ANSWER << '\n';
return 0;
}
"""
Problem 978: Bernoulli Number Modular Sum
Compute sum_{n=0}^{200} (|p_n| + q_n) mod (10^9 + 7),
where B_n = p_n / q_n is the n-th Bernoulli number in lowest terms.
Bernoulli numbers are defined by the exponential generating function:
t / (e^t - 1) = sum B_n * t^n / n!
Key properties:
- B_0 = 1, B_1 = -1/2, B_n = 0 for odd n >= 3
- |B_{2n}| grows roughly as 2 * (2n)! / (2*pi)^{2n}
- Denominators follow the Von Staudt-Clausen theorem:
denom(B_{2n}) = product of primes p where (p-1) | 2n
Answer: computed via exact Fraction arithmetic
Methods:
- compute_bernoulli(n_max): Compute B_0..B_{n_max} via recurrence
- von_staudt_clausen_denominator(n): Predict denominator via theorem
- verify_small_values(): Check known Bernoulli numbers
"""
from fractions import Fraction
from math import comb, log10
MOD = 10**9 + 7
def compute_bernoulli(n_max):
"""Compute B_0 to B_{n_max} using the standard recurrence."""
B = [Fraction(0)] * (n_max + 1)
B[0] = Fraction(1)
for n in range(1, n_max + 1):
B[n] = -sum(Fraction(comb(n + 1, k)) * B[k] for k in range(n)) / (n + 1)
return B
def von_staudt_clausen_denominator(n):
"""
For even n >= 2, denom(B_n) = product of primes p where (p-1) | n.
"""
if n == 0:
return 1
if n == 1:
return 2
if n % 2 == 1:
return 1 # B_n = 0 for odd n >= 3
# Find all primes p where (p-1) divides n
result = 1
# Check primes up to n+1
for p in range(2, n + 2):
# Simple primality check
if p < 2:
continue
is_prime = True
for d in range(2, int(p**0.5) + 1):
if p % d == 0:
is_prime = False
break
if is_prime and n % (p - 1) == 0:
result *= p
return result
def verify_small_values(B):
"""Check known Bernoulli numbers."""
assert B[0] == Fraction(1)
assert B[1] == Fraction(-1, 2)
assert B[2] == Fraction(1, 6)
assert B[4] == Fraction(-1, 30)
assert B[6] == Fraction(1, 42)
assert B[8] == Fraction(-1, 30)
assert B[10] == Fraction(5, 66)
# Odd Bernoulli numbers (>= 3) are zero
for n in range(3, 20, 2):
assert B[n] == 0
return True
# Computation
B = compute_bernoulli(200)
verify_small_values(B)
# Verify Von Staudt-Clausen for even indices
for n in range(0, 50, 2):
if n >= 2:
assert B[n].denominator == von_staudt_clausen_denominator(n), \
f"VSC failed at n={n}: {B[n].denominator} vs {von_staudt_clausen_denominator(n)}"
answer = 0
for n in range(201):
p, q = B[n].numerator, B[n].denominator
answer = (answer + (abs(p) + q) % MOD) % MOD
print(answer)