A Leyland number L(x,y) is x^y + y^x where x>=y>1. OEIS A076980 prepends L(2,1) as its first term. The first ten Leyland number (x,y) pairs ordered by magnitude are (2,1), (2,2), (3,2), (4,2), (3,3), (5,2), (6,2), (4,3), (7,2), (8,2). We wish to efficiently calculate the A076980 index of a given (x,y) pair, understanding that the procedure may be somewhat onerous for large L(x,y). For example, the recently discovered L(101311,90816) probable prime has, by my own admittedly inefficient Mathematica procedure, an index of 6137957218.
It fails for the initial (2,1), but here is the code that I've been using since 2015:
L[{x_, y_}] := x^y + y^x;
LN[{x_, y_}] := (
q = L[{x, y}];
nn = q*.001;
n = 1.0;
count = 2;
While[
n = n + 1.0;
num = 2*n^n;
num < nn || 2*Round[n]^Round[n] < q,
count++;
k = n;
While[
k = k + 1.0;
num = L[{n, k}];
num < nn || L[{Round[n], Round[k]}] < q,
count++
]
];
count
)
Here's a neat application. Assuming the conjecture that (for d > 11) the smallest d-digit Leyland number is L(d-1,10), then the number of d-digit Leyland numbers is LN[{d,10}] - LN[{d-1,10}]. For d = 1000000, this works out to 39542.