Context: I was playing with the numbers 123,456,789 and 987,654,321 which are interesting because they are composed of the digits 1–9 in ascending and descending order, respectively. These numbers are also the 10th terms of the following two sequences, which I investigated further in other bases:
I defined the sequences:
$$ a_n = \sum_{k=0}^{n-1} k \cdot n^{n-k-1}, \quad b_n = \sum_{k=1}^{n-1} k \cdot n^{k-1} $$
For $ n = 1 $ to $ 10 $, I computed:
$$ \begin{aligned} a_n &= 0,\ 1,\ 5,\ 27,\ 194,\ 1865,\ 22875,\ 342391,\ 6053444,\ \mathbf{123456789} \\ b_n &= 0,\ 1,\ 7,\ 57,\ 586,\ 7465,\ 114381,\ 2054353,\ 42374116,\ \mathbf{987654321} \end{aligned} $$
I then checked these sequences for prime values and noticed that only $ a_3 = 5 $ and $ b_3 = 7 $ are prime for $ n < 100 $. I couldn't compute further due to overflow and performance issues, but it appears these might be the only primes in the sequences.
Here's the Python code I used to compute and check primality:
import math
def isprime(n):
n = abs(int(n))
if n < 2:
return False
if n == 2:
return True
if not n & 1:
return False
for x in range(3, int(n**0.5)+1, 2):
if n % x == 0:
return 0
return 1
n=100
p1=[]
p2=[]
sum=0
for i in range(1,n+1):
sum=0
for j in range(0,i):
sum=sum+j*pow(i,i-j-1)
if isprime(sum)==1:
p1.append((i,sum))
for i in range(1,n+1):
sum=0
for j in range(1,i):
sum=sum+j*pow(i,j-1)
if isprime(sum)==1:
p2.append((i,sum))
print(p1)
print(p2)
My question is: Are $a_3 , b_3$ the only primes in their respective sequences?
Another interesting property is
$$\gcd(a_n, b_n)= \begin{cases} n-1, & \text{if $n$ is even} \\ (n-1)/2, & \text{if $n$ is odd} \end{cases}$$ But I couldn't prove/disprove that.