Pandigital Multiples
For a fixed positive integer x, form the concatenated product of x with (1, 2,..., n) for some n > 1. What is the largest 1-to-9 pandigital 9-digit number achievable?
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Take the number $192$ and multiply it by each of $1$, $2$, and $3$: \begin{align} 192 \times 1 &= 192\\ 192 \times 2 &= 384\\ 192 \times 3 &= 576 \end{align} By concatenating each product we get the $1$ to $9$ pandigital, $192384576$. We will call $192384576$ the concatenated product of $192$ and $(1,2,3)$.
The same can be achieved by starting with $9$ and multiplying by $1$, $2$, $3$, $4$, and $5$, giving the pandigital, $918273645$, which is the concatenated product of $9$ and $(1,2,3,4,5)$.
What is the largest $1$ to $9$ pandigital $9$-digit number that can be formed as the concatenated product of an integer with $(1,2, \dots, n)$ where $n \gt 1$?
Problem 38: Pandigital Multiples
Mathematical Development
Definitions
Definition 1. The concatenated product of with the tuple , denoted , is the integer obtained by concatenating the decimal representations of :
where denotes string concatenation interpreted as a decimal numeral.
Definition 2. An integer is 1-to-9 pandigital if its decimal representation consists of the digits each appearing exactly once.
Theoretical Development
Theorem 1 (Digit count constraint). For to be a 9-digit pandigital number with , we require
Proof. The concatenation has exactly digits, where . For 1-to-9 pandigitality, this sum must equal 9.
Theorem 2 (Feasible parameter space). The digit count constraint restricts to finitely many cases. The principal families are:
| Digit pattern | Range of | |
|---|---|---|
| 2 | , with | |
| 3 | ||
| 4 | ||
| 5 | ||
| 9 |
Proof. For : . If , then . For we need , i.e., . If then and , giving .
For : . The minimum total digit count is (when no product has more digits than ). For : . For : the total is at least 6, and we need the remaining products to contribute exactly 3 more digits among two terms, which forces specific ranges.
The remaining cases follow analogously. For , even produces with 11 digits .
Lemma 1 (Leading-digit maximization). Since begins with , maximizing requires maximizing the leading portion, which is itself. Thus should begin with the digit 9.
Proof. For two 9-digit numbers, the one with the lexicographically larger prefix is numerically larger. Since the first digits of are exactly , a larger (in the same digit-count class) produces a larger leading prefix.
Theorem 3 (Optimality of the case). For and , the concatenated product is , a 9-digit number. The maximum pandigital value arises at .
Proof. By Lemma 1, restrict to starting with 9, i.e., with (so , satisfied). The 9-digit number starts with "", already larger than any pandigital from other families (the best case gives starting with “91…”, and any case has , producing numbers starting with at most “3…”).
Within : we search for pandigitality. At :
The digit set is : pandigital.
To verify maximality, observe that for starting with “93”: can be checked — each fails pandigitality due to repeated digits. For starting with “94” through “98”: gives , and the first two digits “94…” already constrain the remaining digits; exhaustive verification shows no pandigital result exceeds . For starting with “99”: starts with “198” or “199”, repeating 9.
Editorial
We enumerate every possible base integer for which the concatenated product could still fit within nine digits, namely . For each , we append the products until the concatenation has at least nine digits, and we keep the value only when the concatenation has exactly nine digits, uses each of the digits 1 through 9 exactly once, and involves at least two factors. The maximum such value is the answer.
Pseudocode
Algorithm: Largest Pandigital Concatenated Product
Require: The decimal digits 1 through 9.
Ensure: The largest 1-to-9 pandigital number that can be written as the concatenated product of an integer with (1, 2, ..., n).
1: Initialize best ← 0.
2: For each base x in {1, 2, ..., 9999}, initialize an empty concatenation C and a multiplier n ← 1.
3: While the length of C is less than 9, append the decimal digits of n · x to C and update n ← n + 1.
4: If C has length 9 and uses each digit 1 through 9 exactly once, update best ← max(best, value(C)).
5: Return best.
Complexity Analysis
Proposition. The algorithm runs in time and auxiliary space, where and .
Proof. The outer loop iterates at most times. For each , the inner loop performs at most 9 concatenations (since 9 single-digit products already fill 9 digits). The pandigital check on a 9-character string is . Total: . Auxiliary space is (a 9-character buffer and integer variables).
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
bool isPandigital(const string& s) {
if (s.size() != 9) return false;
int mask = 0;
for (char c : s) {
if (c == '0') return false;
int d = c - '0';
if (mask & (1 << d)) return false;
mask |= (1 << d);
}
return mask == 0x3FE;
}
int main() {
long long best = 0;
for (int x = 1; x <= 9999; x++) {
string concat;
for (int n = 1; n <= 9; n++) {
concat += to_string((long long)x * n);
if (concat.size() > 9) break;
if (n >= 2 && concat.size() == 9 && isPandigital(concat))
best = max(best, stoll(concat));
}
}
cout << best << endl;
return 0;
}
"""Project Euler Problem 38: Pandigital Multiples"""
def is_pandigital(s):
return len(s) == 9 and set(s) == set("123456789")
best = 0
for x in range(1, 10000):
concat = ""
for n in range(1, 10):
concat += str(x * n)
if len(concat) > 9:
break
if n >= 2 and len(concat) == 9 and is_pandigital(concat):
best = max(best, int(concat))
print(best)