All Euler problems
Project Euler

Permuted Multiples

Find the smallest positive integer x such that 2x, 3x, 4x, 5x, and 6x contain the same digits as x.

Source sync Apr 19, 2026
Problem #0052
Level Level 01
Solved By 72,129
Languages C++, Python
Answer 142857
Length 432 words
combinatoricsmodular_arithmeticsearch

Problem Statement

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

It can be seen that the number, \(125874\), and its double, \(251748\), contain exactly the same digits, but in a different order.

Find the smallest positive integer, \(x\), such that \(2x\), \(3x\), \(4x\), \(5x\), and \(6x\), contain the same digits.

Problem 52: Permuted Multiples

Mathematical Development

Formal Development

Definition 1 (Digit Multiset). For a positive integer nn with decimal representation dk1dk2d0d_{k-1} d_{k-2} \cdots d_0, define D(n)\mathcal{D}(n) as the sorted multiset of its decimal digits. Formally, D(n)=sort(dk1,dk2,,d0)\mathcal{D}(n) = \text{sort}(d_{k-1}, d_{k-2}, \ldots, d_0).

Definition 2 (Permuted Multiple Property). An integer xx satisfies the permuted multiple property up to factor mm if D(kx)=D(x)\mathcal{D}(kx) = \mathcal{D}(x) for all k{1,2,,m}k \in \{1, 2, \ldots, m\}.

Lemma 1 (Digit Count Preservation). If D(x)=D(6x)\mathcal{D}(x) = \mathcal{D}(6x), then xx and 6x6x have the same number of digits.

Proof. Two integers share the same digit multiset only if they have the same number of digits (the multiset determines the digit count). \blacksquare

Proposition 1 (Search Range Restriction). If xx has exactly dd digits and satisfies the permuted multiple property up to factor 6, then

10d1x<10d6.10^{d-1} \leq x < \frac{10^d}{6}.

Proof. Since xx has dd digits, x10d1x \geq 10^{d-1}. By Lemma 1, 6x6x also has dd digits, so 6x10d1<10d6x \leq 10^d - 1 < 10^d, giving x<10d/6x < 10^d / 6. \blacksquare

Theorem 1 (Cyclic Numbers and Primitive Roots). Let pp be a prime such that ordp(10)=p1\mathrm{ord}_p(10) = p - 1 (i.e., 10 is a primitive root modulo pp). Define Np=(10p11)/pN_p = (10^{p-1} - 1)/p. Then NpN_p is a cyclic number: for each k{1,2,,p1}k \in \{1, 2, \ldots, p-1\}, the product kNpk \cdot N_p is a cyclic permutation of the digits of NpN_p.

Proof. Since ordp(10)=p1\mathrm{ord}_p(10) = p - 1, the decimal expansion of 1/p1/p has period exactly p1p - 1. Write

1p=0.d1d2dp1,\frac{1}{p} = 0.\overline{d_1 d_2 \cdots d_{p-1}},

so Np=d1d2dp1N_p = d_1 d_2 \cdots d_{p-1} and Npp=10p11=999p1N_p \cdot p = 10^{p-1} - 1 = \underbrace{99\cdots9}_{p-1}.

For 1kp11 \leq k \leq p - 1, consider k/p(mod1)k/p \pmod{1}. Since 10 is a primitive root modulo pp, the fractional part of k/pk/p has the same repeating block as 1/p1/p but cyclically shifted. Specifically, there exists an integer jj (depending on kk) such that

kp=0.djdj+1dp1d1dj1.\frac{k}{p} = 0.\overline{d_j d_{j+1} \cdots d_{p-1} d_1 \cdots d_{j-1}}.

Thus kNpk \cdot N_p is the integer formed by this cyclic shift. Since cyclic permutations preserve digit multisets, D(kNp)=D(Np)\mathcal{D}(k \cdot N_p) = \mathcal{D}(N_p). \blacksquare

Corollary 1. For p=7p = 7, we have ord7(10)=6=71\mathrm{ord}_7(10) = 6 = 7 - 1, so N7=(1061)/7=142857N_7 = (10^6 - 1)/7 = 142857 is a cyclic number. In particular:

1×142857=142857,2×142857=285714,3×142857=428571,4×142857=571428,5×142857=714285,6×142857=857142.\begin{aligned} 1 \times 142857 &= 142857, \\ 2 \times 142857 &= 285714, \\ 3 \times 142857 &= 428571, \\ 4 \times 142857 &= 571428, \\ 5 \times 142857 &= 714285, \\ 6 \times 142857 &= 857142. \end{aligned}

Each product is a cyclic permutation of 142857, hence D(k142857)=D(142857)\mathcal{D}(k \cdot 142857) = \mathcal{D}(142857) for k=1,,6k = 1, \ldots, 6.

Theorem 2 (Minimality of 142857). The value x=142857x = 142857 is the smallest positive integer satisfying D(kx)=D(x)\mathcal{D}(kx) = \mathcal{D}(x) for k=2,3,4,5,6k = 2, 3, 4, 5, 6.

Proof. By Proposition 1, for each digit count dd, the search range is [10d1,10d/6][10^{d-1}, \lfloor 10^d / 6 \rfloor].

ddRangeSize
1[1,1][1, 1]1
2[10,16][10, 16]7
3[100,166][100, 166]67
4[1000,1666][1000, 1666]667
5[10000,16666][10000, 16666]6667
6[100000,166666][100000, 166666]66667

Exhaustive computation over d=1,,5d = 1, \ldots, 5 yields no solution. For d=6d = 6, the value x=142857x = 142857 satisfies the property by Corollary 1. No smaller 6-digit value in [100000,142856][100000, 142856] satisfies the condition (verified computationally). \blacksquare

Editorial

We search the positive integers in increasing order and compare each candidate with its first five nontrivial multiples. For a given value xx, we compute its canonical digit signature by sorting its decimal digits, then test whether the same signature appears for 2x,3x,4x,5x,2x,3x,4x,5x, and 6x6x. The first integer that passes all five comparisons is the smallest solution.

Pseudocode

Algorithm: Smallest Integer Whose First Six Multiples Are Digit Permutations
Require: The positive integers.
Ensure: The least x such that 2x, 3x, 4x, 5x, and 6x are permutations of the digits of x.
1: Initialize x ← 1.
2: Repeat:
3:     Compute the canonical digit signature sigma(x).
4:     If sigma(x) = sigma(2x) = sigma(3x) = sigma(4x) = sigma(5x) = sigma(6x), return x; otherwise update x ← x + 1.

Complexity Analysis

Proposition 2 (Time). The algorithm terminates after examining at most d=1610d/610d1+174076\sum_{d=1}^{6} \lfloor 10^d/6 \rfloor - 10^{d-1} + 1 \leq 74076 candidates. Each candidate requires 5 sorted-digit comparisons, each costing O(dlogd)O(d \log d). With d6d \leq 6, each comparison is O(1)O(1). Total: O(74076)=O(1)O(74076) = O(1).

Proposition 3 (Space). O(d)=O(1)O(d) = O(1) for digit arrays.

Answer

142857\boxed{142857}

Code

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

C++ project_euler/problem_052/solution.cpp
#include <bits/stdc++.h>
using namespace std;

string sorted_digits(int n) {
    string s = to_string(n);
    sort(s.begin(), s.end());
    return s;
}

int main() {
    for (int x = 1; ; x++) {
        string sd = sorted_digits(x);
        bool ok = true;
        for (int k = 2; k <= 6; k++) {
            if (sorted_digits(k * x) != sd) {
                ok = false;
                break;
            }
        }
        if (ok) {
            cout << x << endl;
            return 0;
        }
    }
    return 0;
}