Double palindromes in {2, 8} - modulo approach? 513 a + 72 b = 513 c + 258 d + 132 e + 72 f + 48 g Trivial subset: 513 * 1 + 72 * 1 = 513 * 1 + 72 * 1 513 and 72 are also palindromic in both. In general, since the base 8 factors are equal to a subset of the base 2 factors, and 1 is allowed in both, all permutations of 1 and 0 in the common factors are palindromic in both bases. Sketch of proof that the base 8 is a subset of the base 2. Since both 8 and 2 are of the form 2^k, each base 8 digit will map directly to a set of base 2 digits. This is easier to show with a representation 371 (base 8) = 011 111 001 (base 2) 301 (base 8) = 011 000 001 (base 2) 070 (base 8) = 000 111 000 (base 2) Furthermore, this shows that searching for double palindromes in base 2/8 is polynomial wrt each double palindrome found (which is not the case for 2/10). The algorithm: For each digit in base 8 (highest base): Try every instance of this digit (0..8). If double-palindromic, record it along with the digit. Next For a_0 = each recorded number with digit type = last For a_1 each recorded number with digit type = next to last etc print a_0 + a_1 + ... Next Next