3

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.

pie
  • 8,483
  • $a_n = (n^n-n^2+n-1)/(n-1)^2$ and $b_n = ((n+1)^{(n+1)}*(n-1)+1)/n^2$ Not sure if it helps – Aurel-BG May 16 '25 at 19:08
  • I think your formula for $b_n$ is wrong, @Aurel-BG I haven't checked $a_n.$ – Thomas Andrews May 16 '25 at 19:51
  • $b_n=f_n'(n)$ when $f_n(x)=\frac{x^n-1}{x-1}.$ Then $$f_n'(x)=\frac{(n-1)x^n-nx^{n-1}+1}{(x-1)^2}.$$ So $$b_n=\frac{(n-1)n^n-n\cdot n^{n-1}+1}{(n-1)^2}=\frac{n^{n+1}-2n^n+1}{(n-1)^2}$$ – Thomas Andrews May 16 '25 at 20:01
  • 1
    @pie Do you know how to prove the unjustified claims in the answer you accepted? (cf. my comment on that answer). If not you should ask for elaboration. Note that no ad hoc guessing or ingenuity is needed if we use the Euclidean algorithm, and the arithmetic is simpler (and this way answers both of your questions), as I explain in my answer and comments on it. $\ \ $ – Bill Dubuque May 19 '25 at 02:27

3 Answers3

6

Modulo $n-1$ both series are simply $1+2+...+ (n-1)$ and are therefore divisible by $$\begin{cases} n-1, & \text{if $n$ is even} \\ (n-1)/2, & \text{if $n$ is odd} \end{cases}$$ This gives you the required result about primality.

Now let $S$ be the integer, coprime to $n$, such that$$1+n+...+n^{n-2}=(n-1)S.$$ Then $$b_n=1+2n +...(n-1)n^{n-2}=n^{n-1}-S$$ and is coprime to $n$ and $S$.

Since $a_n+b_n=n(n-1)S$ the GCD is a divisor of $n(n-1)S$ and is therefore a divisor of $n-1$. From the primality argument your second conjecture is therefore also true.

user1172706
  • 2,791
3

Just to answer the GCD part of the question..

You can get the closed forms for $a_n,b_n:$

$$ \begin{align} a_n&=\frac{n^n-n^2+n-1}{(n-1)^2}\\ b_n&=\frac{n^{n+1}-2n^n+1}{(n-1)^2} \end{align}$$

Then you can show $$b_n-(n-2)a_n=n-1$$

That means the GCD is a divisor of $n-1.$ But the other answer shows that$$a_n,b_n\equiv 0\text{ or }\frac{n-1}2\pmod{n-1}$$ depending on whether $n$ is even or odd, thus validating your conjecture.

Thomas Andrews
  • 186,215
  • My answer explains how to mechanically derive the key equation $,b_n-(n!-!2)a_n=n-1,,$ by using the $\rm\color{#0a0}{polynomial}$ Euclidean algorithm. Although the $\rm\color{#c00}{exponential}$ expressions (in $,n^n,$ etc) are simple enough here that one might be able to derive the equation in an ad-hoc way without too much difficulty, that will prove much more difficult for larger such expressions. But the Euclidean algorithm always works - efficiently and uniformly (no ingenuity is needed), no matter how complex the $\rm\color{#0a0}{polynomial}$ expressions. $\ \ $ – Bill Dubuque May 17 '25 at 06:45
2

The gcd is a mental mechanical calculation by the Euclidean $\rm\color{#90f}{division}$ algorithm. But the key idea is that we must do this for the generating polynomials in $\:\!x,\,$ i.e. before evaluating them at $\,x=n\,$ (which maps polynomials like $\,x^n\,$ into exponentials $\,n^n\,$ so Euclid's algorithm no longer applies).

We seek the gcd $\:\!(a_n,b_n)\:\!$ for $\:\!b_x = [\:\!(x^n\!-\!1)/(x\!-\!1)]'\:\!$ and $\:\!a_x\:\!$ is its reverse polynomial i.e.

$$ b_x = \dfrac{(\color{#0a0}{(n\!-\!1)x\!-\!n})x^{n-1}+1}{(x\!-\!1)^2} =:\dfrac{\!\!B}{(x\!-\!1)^2}\qquad$$

$$ a_x = \dfrac{x^n-nx+n\!-\!1}{(x\!-\!1)^2} =: \dfrac{\!\!A}{(x\!-\!1)^2}$$

so $\ \ xB-(\color{#0a0}{(n\!-\!1)x\!-\!n})A = n(n\!-\!1)(x\!-\!1)^2\,$ by $\rm\color{#90f}{division}$ $\,xB\div A$

so $\ \ \,\color{#0af}{b_n}-(n\!-\!2)a_n = \color{#0af}{n\!-\!1}\ $ by eval at $\:\!x=n\:\!$ then cancel $\:\!n(n\!-\!1)^2$

so $\,\ \ (a_n,\color{#0af}{b_n}) = (a_n,\color{#0af}{n\!-\!1})\ $ by $\:\!\rm\color{brown}{Euclid}\:\!$ & $\,\color{#0af}{b_n\equiv n\!-\!1}\pmod{\!a_n}$

so $\,\ \bbox[6px,border:2px solid #0a0]{\! (\color{#f40}{a_n},b_n) = (\color{#f40}{n(n\!-\!1)/2},\:\!n\!-\!1) = n\!-\!1\,\ {\rm if}\ \,2\mid n,\ {\rm else}\ \,(n\!-\!1)/2}$

by $\ \ \ \:\!\color{#f40}{a_n}\!\equiv a_1\! \equiv\sum_{k=1}^{n-1} k\equiv \color{#f40}{\frac{n(n-1)}2}\!\pmod{\!n\!-\!1}\,$ and $\rm\color{brown}{Euclid}$.

J. W. Tanner
  • 63,683
  • 4
  • 43
  • 88
Bill Dubuque
  • 282,220
  • 1
    By above $,a_n,b_n$ are both divisible by $,d = n!-!1$ or $,(n!-!1)/2,$ for $:!n:!$ even or odd resp. For $,n>3,$ we have $, 1 < d < a_n,b_n,$ so $,d,$ is a proper factor, thus you have found all of the primes in $,a_n,b_n.,$Therefore the above gcd calculation answers both of your questions (without pulling anything out of a hat like magic, i.e. discovery of the proper factor and division reduction step occur naturally during the Euclidean algorithm). $\ \ $ – Bill Dubuque May 17 '25 at 08:07
  • 1
    ${\rm\color{brown}{\text{Euclid:}}}\ \ A\equiv a\pmod{! m},\Rightarrow\ (A,m) = (a,m),,$ i.e. gcd mod reduction, is what we used above to compute the gcd (it's a generalization of $, (A,m) = (A\bmod m,,m)$ = descent step in the Euclidean algorithm). – Bill Dubuque May 19 '25 at 01:59