Primes and moduli P45675


Statement
 

pdf   zip

Let pnp_n be the nnth prime number (starting at 0): p0=2,p1=3,p2=5,p3=7,p_0 = 2, p_1 = 3, p_2 = 5, p_3 = 7, \dots Define rnr_n as the remainder of (pn+1)n+(pn1)n\left(p_n + 1 \right) ^n + \left(p_n - 1 \right)^n modulo (pn)2({p_n})^2. For instance, r3=42r_3 = 42, because (7+1)3+(71)3=512+216=728=1449+42.\begin{equation*} (7+1)^3 + (7-1)^3 \enspace = \enspace 512 + 216 \enspace = \enspace 728 \enspace = \enspace 14 \cdot 49 + 42 \enspace . \end{equation*}

Given two integer numbers aa and bb, find the largest rir_i such that i[a,b]i \in \left[ a, b \right].

Input

Input consists of several cases, each one with two integer numbers aa and bb, where 0ab0 \le a \le b and pb107p_b \le 10^7.

Output

For every case, print the largest rir_i such that i[a,b]i \in \left[ a, b \right].

Public test cases
  • Input

    1 1
    2 2
    1 2
    3 3
    1 10
    1 100
    1 1000
    600000 600002
    

    Output

    6
    2
    6
    42
    522
    107118
    15822162
    10752590320954
    
  • Information
    Author
    Albert Graells
    Language
    English
    Official solutions
    C++
    User solutions
    C++