Skip to content

Problem 952: Order Modulo Factorial

Problem 952: Order Modulo Factorial

Given a prime pp and a positive integer n<pn < p, let R(p,n)R(p, n) be the multiplicative order of pp modulo n!n!.

In other words, R(p,n)R(p, n) is the minimal positive integer rr such that

pr1(modn!)p^r \equiv 1 \pmod{n!}

For example, R(7,4)=2R(7, 4) = 2 and R(109+7,12)=17280R(10^9 + 7, 12) = 17280.

Find R(109+7,107)R(10^9 + 7, 10^7). Give your answer modulo 109+710^9 + 7.

Strategy: Chinese Remainder Theorem and Orders

Section titled “Strategy: Chinese Remainder Theorem and Orders”

The congruence pr1(modn!)p^r \equiv 1 \pmod{n!} can be broken down into a system of congruences for each prime power factor of n!n!. Let the prime factorization of n!n! be n!=qnqvq(n!)n! = \prod_{q \le n} q^{v_q(n!)}, where qq are primes and vq(n!)v_q(n!) is the exponent of qq in the factorization, given by Legendre’s formula: vq(n!)=k=1n/qkv_q(n!) = \sum_{k=1}^{\infty} \lfloor n/q^k \rfloor.

By the Chinese Remainder Theorem, the congruence is equivalent to the system:

pr1(modqvq(n!))for all primes qnp^r \equiv 1 \pmod{q^{v_q(n!)}} \quad \text{for all primes } q \le n

For this system to hold, rr must be a multiple of the multiplicative order of pp modulo each prime power qvq(n!)q^{v_q(n!)}. The minimal such positive rr is therefore the least common multiple (LCM) of these orders.

R(p,n)=lcm{ordqvq(n!)(p)qn is prime}R(p, n) = \text{lcm} \{ \text{ord}_{q^{v_q(n!)}}(p) \mid q \le n \text{ is prime} \}

The core of the problem is to find ordqa(p)\text{ord}_{q^a}(p), the order of pp modulo a prime power qaq^a. This can be determined from the order modulo qq using a principle often called the “Lifting The Exponent Lemma for Orders”.

  1. For odd primes qq: Let k=ordq(p)k = \text{ord}_q(p). Then ordqa(p)=kqac\text{ord}_{q^a}(p) = k \cdot q^{a-c}, where c=vq(pk1)c = v_q(p^k - 1).

  2. For the prime q=2q=2: Let k=ord2(p)=1k = \text{ord}_2(p) = 1. Then ord2a(p)\text{ord}_{2^a}(p) depends on v2(p21)v_2(p^2-1). Specifically, for ac=v2(p21)a \ge c = v_2(p^2-1), the order is ord2a(p)=22ac=2ac+1\text{ord}_{2^a}(p) = 2 \cdot 2^{a-c} = 2^{a-c+1}.

The prime factorization of the answer R(p,n)R(p, n) is ses\prod s^{e_s}. The exponent ese_s for each prime ss is the maximum power of ss found among all the orders ordqvq(n!)(p)\text{ord}_{q^{v_q(n!)}}(p).

es=maxqn{vs(ordqvq(n!)(p))}e_s = \max_{q \le n} \{ v_s(\text{ord}_{q^{v_q(n!)}}(p)) \}

Analysis shows that for a large nn, the term vs(n!)v_s(n!) is significantly larger than any other contributing factor. This leads to a major simplification: the exponent ese_s is dominated by the case where s=qs=q.

esvs(ordsvs(n!)(p))=vs(n!)vs(pords(p)1)+δe_s \approx v_s(\text{ord}_{s^{v_s(n!)}}(p)) = v_s(n!) - v_s(p^{\text{ord}_s(p)}-1) + \delta

(where δ\delta is 1 for s=2s=2 and 0 otherwise).

The term vs(pords(p)1)v_s(p^{\text{ord}_s(p)}-1) is almost always 1. A value greater than 1 occurs only if pords(p)1(mods2)p^{\text{ord}_s(p)} \equiv 1 \pmod{s^2}, which implies ps11(mods2)p^{s-1} \equiv 1 \pmod{s^2}. Primes ss with this property (for a given base pp) are called Wieferich primes and are exceptionally rare.

We are given p=109+7p = 10^9 + 7 and n=107n = 10^7. We can make the standard and safe assumption that for p=109+7p=10^9+7, no odd Wieferich primes exist up to 10710^7.

  • For odd primes qnq \le n: We assume vq(pordq(p)1)=1v_q(p^{\text{ord}_q(p)}-1) = 1. The exponent of qq in the final answer is vq(n!)1v_q(n!) - 1.
  • For the prime q=2q=2: We must calculate c2=v2(p21)c_2 = v_2(p^2-1). p=109+77(mod8)p = 10^9+7 \equiv 7 \pmod 8. p1=109+6p-1 = 10^9+6, so v2(p1)=1v_2(p-1)=1. p+1=109+8p+1 = 10^9+8, so v2(p+1)=3v_2(p+1)=3. c2=v2(p21)=v2(p1)+v2(p+1)=1+3=4c_2 = v_2(p^2-1) = v_2(p-1) + v_2(p+1) = 1+3=4. The exponent of 2 in the answer is v2(n!)4+1=v2(n!)3v_2(n!) - 4 + 1 = v_2(n!) - 3.

Combining these results, the final answer A=R(p,n)A = R(p, n) is:

A=2v2(n!)3qnq odd primeqvq(n!)1A = 2^{v_2(n!)-3} \cdot \prod_{\substack{q \le n \\ q \text{ odd prime}}} q^{v_q(n!)-1}

We can rewrite this formula by factoring out n!=qnqvq(n!)n! = \prod_{q \le n} q^{v_q(n!)}:

A=qnqvq(n!)23qn,q oddq1=n!82<qnqA = \frac{\prod_{q \le n} q^{v_q(n!)}}{2^3 \cdot \prod_{q \le n, q \text{ odd}} q^1} = \frac{n!}{8 \cdot \prod_{2 < q \le n} q}

The problem asks for this value modulo p=109+7p = 10^9+7. The final computation is:

An!(8)1(2<qnq)1(modp)A \equiv n! \cdot (8)^{-1} \cdot \left(\prod_{2 < q \le n} q\right)^{-1} \pmod{p}

This can be calculated efficiently:

  1. Compute n!(modp)n! \pmod{p}.
  2. Use a prime sieve to find all primes qq from 33 to n=107n=10^7.
  3. Compute the product of these primes modulo pp.
  4. Find the modular multiplicative inverses of 8 and the product of primes.
  5. Multiply all the components together modulo pp to get the final answer.