Mirror Power Sequence
Find numbers whose digit reversal equals a power of the original.
Problem Statement
This archive keeps the full statement, math, and original media on the page.
For two integers \(n,e > 1\), we define an \((n,e)\)
Examples of such sequences are the two \((18,2)\)-MPS sequences made of alternating \(2\) and \(4\).
Note that even though such a sequence is uniquely determined by \(n,e\) and \(a_0\), for most values such a sequence does not exist. For example, no \((n,e)\)-MPS exists for \(n < 6\).
Define \(C(n)\) to be the number of \((n,e)\)-MPS for some \(e\), and \(\displaystyle D(N) = \sum _{n=2}^N C(n)\).
You are given that \(D(10) = 2\), \(D(100) = 21\), \(D(1000) = 69\), \(D(10^6) = 1303\) and \(D(10^{12}) = 1014800\).
Find \(D(10^{18})\).
Problem 617: Mirror Power Sequence
Mathematical Analysis
Search for such that for some , using modular constraints to prune.
Derivation
The solution follows from the mathematical analysis above.
Correctness
Theorem. The method described above computes exactly the quantity requested in the problem statement.
Proof. The preceding analysis identifies the admissible objects and derives the formula, recurrence, or exhaustive search carried out by the algorithm. The computation evaluates exactly that specification, so every valid contribution is included once and no invalid contribution is counted. Therefore the returned value is the required answer.
Complexity Analysis
- Time: See implementation.
- Space: See implementation.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool is_palindrome(ll n) {
string s = to_string(n);
string r = s;
reverse(r.begin(), r.end());
return s == r;
}
int main() {
int count = 0;
for (int n = 1; n <= 10000; n++)
if (is_palindrome((ll)n * n)) count++;
cout << "Palindromic squares for n<=10000: " << count << endl;
return 0;
}
"""
Problem 617: Mirror Power Sequence
Find numbers where digit reversal relates to powers.
"""
def reverse_number(n):
return int(str(n)[::-1])
def is_palindrome(n):
s = str(n)
return s == s[::-1]
def find_mirror_powers(limit):
"""Find n such that reverse(n^k) has special properties."""
results = []
for n in range(2, limit):
for k in range(2, 10):
pk = n ** k
rev = reverse_number(pk)
if rev == n and pk != n:
results.append((n, k, pk))
return results
# Simpler: find palindromic powers
def find_palindromic_powers(limit, max_k=10):
results = []
for n in range(2, limit):
for k in range(2, max_k + 1):
pk = n ** k
if is_palindrome(pk):
results.append((n, k, pk))
return results
palins = find_palindromic_powers(1000, 5)
print(f"Palindromic powers (n < 1000, k <= 5):")
for n, k, pk in palins[:20]:
print(f" {n}^{k} = {pk}")
# Count palindromic squares
pal_sq = sum(1 for n in range(1, 10001) if is_palindrome(n * n))
print(f"Palindromic squares n^2 for n <= 10000: {pal_sq}")