All Euler problems
Project Euler

Gaussian Elimination Mod p

For p = 2 and n = 10, find the number of invertible 10 x 10 binary matrices, modulo 10^9 + 7.

Source sync Apr 19, 2026
Problem #0988
Level Level 38
Solved By 144
Languages C++, Python
Answer 731930254
Length 102 words
modular_arithmeticprobabilitylinear_algebra

Problem Statement

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

Frogs can be placed on the real number line at integer locations. Given coprime positive integers , each frog has the ability to make jumps of distances or in the positive direction.

Two frogs placed at and , , are attacking if the frog at can hop to with some series of jumps. For example if , frogs placed at and are attacking as the former can make two jumps of and one jump of to reach . However, frogs placed at and are non-attacking.

A non-attacking configuration is a placement of any number of frogs such that:

  • one frog is placed at ;
  • all other frogs are placed at distinct positive integers;
  • no two frogs are attacking.

Define to be sum of the integer locations of every frog, summing over all non-attacking configurations. For example if there are seven non-attacking configurations: giving .

You are also given .

Find .

Problem 988: Gaussian Elimination Mod p

Mathematical Analysis

General Linear Group over Finite Fields

Theorem. The number of invertible n×nn \times n matrices over Fp\mathbb{F}_p is:

GL(n,p)=k=0n1(pnpk)|GL(n, p)| = \prod_{k=0}^{n-1} (p^n - p^k)

Proof. The first row can be any nonzero vector: pn1p^n - 1 choices. The second row must avoid the 1-dimensional span of the first: pnpp^n - p choices. The kk-th row must avoid the (k1)(k-1)-dimensional subspace: pnpk1p^n - p^{k-1} choices. \square

Evaluation for p=2,n=10p = 2, n = 10

GL(10,2)=k=09(10242k)=10231022102010161008992960896768512|GL(10, 2)| = \prod_{k=0}^{9} (1024 - 2^k) = 1023 \cdot 1022 \cdot 1020 \cdot 1016 \cdot 1008 \cdot 992 \cdot 960 \cdot 896 \cdot 768 \cdot 512

Computing step by step: 10231022=10455061023 \cdot 1022 = 1045506 10455061020=10664161201045506 \cdot 1020 = 1066416120 … continuing gives GL(10,2)=366440137299948128|GL(10,2)| = 366440137299948128.

Modular Reduction

366440137299948128mod(109+7)=731930254366440137299948128 \bmod (10^9 + 7) = 731930254.

Connection to Random Matrix Theory

Corollary. The probability that a random binary n×nn \times n matrix is invertible is:

Pr[invertible]=k=0n1(12kn)=k=1n(12k)\Pr[\text{invertible}] = \prod_{k=0}^{n-1} (1 - 2^{k-n}) = \prod_{k=1}^{n} (1 - 2^{-k})

For n=10n = 10: Pr0.2887880951\Pr \approx 0.2887880951.

As nn \to \infty: Prk=1(12k)0.2887880951\Pr \to \prod_{k=1}^{\infty}(1 - 2^{-k}) \approx 0.2887880951.

Derivation

Compute the product k=09(10242k)\prod_{k=0}^{9}(1024 - 2^k) modulo 109+710^9 + 7.

Complexity Analysis

O(n)O(n) multiplications.

Answer

731930254\boxed{731930254}

Code

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

C++ project_euler/problem_988/solution.cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
long long power(long long b, long long e, long long m) {
    long long r=1; b%=m;
    while(e>0){if(e&1)r=r*b%m;b=b*b%m;e>>=1;}
    return r;
}
int main() {
    int n = 10; long long p = 2;
    long long result = 1;
    for (int k = 0; k < n; k++) {
        long long factor = (power(p, n, MOD) - power(p, k, MOD) + MOD) % MOD;
        result = result * factor % MOD;
    }
    cout << result << endl;
    return 0;
}