Double Pandigital Number Divisible by 11
We call a positive integer double pandigital if it uses all the digits 0 to 9 exactly twice (with no leading zero). How many double pandigital numbers are divisible by 11?
Problem Statement
This archive keeps the full statement, math, and original media on the page.
We call a positive integer
How many double pandigital numbers are divisible by \(11\)?
Problem 491: Double Pandigital Number Divisible by 11
Notation
Throughout, a double pandigital number is a 20-digit string (with ) in which every digit appears exactly twice. Positions are called odd positions and positions are called even positions. We write and .
Mathematical Foundation
Theorem 1 (Divisibility rule for 11). An integer with decimal representation satisfies if and only if .
Proof. Since , we have for all . Therefore
For (even), , so . Hence if and only if .
Lemma 1 (Reduction to a single congruence). The divisibility condition is equivalent to .
Proof. Since every digit appears exactly twice, the total digit sum is . Thus , giving . The condition becomes , i.e., . Now , so . Hence . Since , we may divide both sides by (equivalently, multiply by ) to obtain .
Definition (Assignment vector). An assignment vector is a tuple satisfying , where denotes the number of copies of digit placed at odd positions. The complementary count at even positions is .
Lemma 2 (Feasible values of ). Under any assignment vector , the odd-position sum is . Since and , we have . The values satisfying in are exactly
Proof. The minimum of is (attained when for and otherwise) and the maximum is (attained when for ). The integers congruent to in are . The value does not satisfy the congruence, nor does .
Theorem 2 (Counting formula). For a valid assignment vector (i.e., and ), the number of double pandigital numbers with no leading zero is
Proof. Given , the 10 odd-position slots receive copies of digit for each . The number of distinct permutations of these 10 items is the multinomial coefficient . Similarly, the 10 even-position slots receive copies of each digit , yielding permutations. Since the choices for odd and even positions are independent, the total number of 20-digit strings (including those with a leading zero) is the product of these two multinomials.
To exclude leading zeros: position 1 is an odd-position slot. A leading zero occurs precisely when digit occupies position 1. If , we can fix one zero at position 1 and permute the remaining odd-position digits (consisting of zeros and copies of each ) in ways. Multiplying by the even-position count and subtracting yields the formula. If , no odd-position slot contains a zero, so the leading digit is never zero and no subtraction is needed.
Corollary. The answer is .
Editorial
We enumerate the admissible parameter range, discard candidates that violate the derived bounds or arithmetic constraints, and update the final set or total whenever a candidate passes the acceptance test.
Pseudocode
answer = 0
For each each (c_0, c_1, ..., c_9) in {0,1,2}^10:
If sum(c_d) != 10 then continue
O = sum(d * c_d for d = 0..9)
If O mod 11 != 1 then continue
odd_perms = 10! / prod(c_d!)
even_perms = 10! / prod((2 - c_d)!)
total = odd_perms * even_perms
If c_0 >= 1 then
leading_zero = 9! / ((c_0 - 1)! * prod(c_d! for d=1..9)) * even_perms
total -= leading_zero
answer += total
Return answer
Complexity Analysis
- Time: . There are candidate vectors, each processed in arithmetic operations.
- Space: auxiliary (beyond the precomputed table of ).
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main(){
// Each digit 0-9 appears exactly twice in a double pandigital number (20 digits).
// We choose c[d] in {0,1,2} copies of digit d to place at odd positions (10 positions).
// Sum of c[d] must be 10.
// Divisibility by 11: O - E ≡ 0 (mod 11) where O = sum of odd-position digits.
// O + E = 90, so O ≡ 1 (mod 11).
long long fact[11];
fact[0] = 1;
for(int i = 1; i <= 10; i++) fact[i] = fact[i-1] * i;
// We enumerate choices c[0..9] in {0,1,2}, sum = 10
// For each valid choice, count = (10! / prod c[d]!) * (10! / prod (2-c[d])!)
// Then subtract leading-zero cases.
long long total = 0;
long long leading_zero = 0;
// Use recursion or iterative enumeration
// c[d] in {0,1,2}, 10 digits -> 3^10 = 59049 combos
int c[10];
// iterate over all 3^10 combinations
for(int mask = 0; mask < 59049; mask++){
int tmp = mask;
int sum_c = 0;
int sum_val = 0;
bool valid = true;
for(int d = 0; d < 10; d++){
c[d] = tmp % 3;
tmp /= 3;
sum_c += c[d];
sum_val += d * c[d];
}
if(sum_c != 10) continue;
if(sum_val % 11 != 1) continue;
// Count permutations for odd positions: 10! / prod(c[d]!)
long long odd_perms = fact[10];
for(int d = 0; d < 10; d++) odd_perms /= fact[c[d]];
// Count permutations for even positions: 10! / prod((2-c[d])!)
long long even_perms = fact[10];
for(int d = 0; d < 10; d++) even_perms /= fact[2 - c[d]];
long long ways = odd_perms * even_perms;
total += ways;
// Leading zero: digit 0 is at position 1 (odd position).
// If c[0] >= 1, fix one 0 at position 1, remaining 9 odd positions
// have the other digits. The count of such arrangements:
// (c[0]/10) * odd_perms * even_perms ... but more precisely:
// Among odd_perms arrangements, fraction c[0]/10 have 0 in the first spot.
if(c[0] >= 1){
// Number of odd arrangements with 0 in first position:
// Fix 0 there. Remaining 9 positions: (9! / ((c[0]-1)! * prod_{d>0} c[d]!))
long long odd_lz = fact[9];
odd_lz /= fact[c[0] - 1];
for(int d = 1; d < 10; d++) odd_lz /= fact[c[d]];
leading_zero += odd_lz * even_perms;
}
}
cout << total - leading_zero << endl;
return 0;
}
from math import factorial
from itertools import product
def solve():
"""
Count double pandigital numbers divisible by 11.
A 20-digit number using each of 0-9 exactly twice is divisible by 11
iff the odd-position digit sum O satisfies O = 1 (mod 11).
We enumerate assignment vectors c in {0,1,2}^10 with sum 10,
filter on sum(d*c_d) = 1 (mod 11), and count permutations
minus leading-zero arrangements.
"""
fact = [factorial(i) for i in range(11)]
answer = 0
for combo in product(range(3), repeat=10):
if sum(combo) != 10:
continue
if sum(d * combo[d] for d in range(10)) % 11 != 1:
continue
odd_perms = fact[10]
even_perms = fact[10]
for d in range(10):
odd_perms //= fact[combo[d]]
even_perms //= fact[2 - combo[d]]
ways = odd_perms * even_perms
if combo[0] >= 1:
lz = fact[9] // fact[combo[0] - 1]
for d in range(1, 10):
lz //= fact[combo[d]]
ways -= lz * even_perms
answer += ways
print(answer)
solve()