Primes and moduli

Let p_(n) be the nth prime number (starting at 0):
p₀ = 2, p₁ = 3, p₂ = 5, p₃ = 7, … Define r_(n) as the remainder of
(p_(n) + 1)^(n) + (p_(n) − 1)^(n) modulo (p_(n))². For instance,
r₃ = 42, because
(7 + 1)³ + (7 − 1)³ = 512 + 216 = 728 = 14 ⋅ 49 + 42 .

Given two integer numbers a and b, find the largest r_(i) such that
i ∈ [a, b].

Input

Input consists of several cases, each one with two integer numbers a and
b, where 0 ≤ a ≤ b and p_(b) ≤ 10⁷.

Output

For every case, print the largest r_(i) such that i ∈ [a, b].

Problem information

Author: Albert Graells

Generation: 2026-01-25T11:19:12.426Z

© Jutge.org, 2006–2026.
https://jutge.org
