login
Difference between a nontrivial prime power (A025475) and the previous prime.
1

%I #12 Sep 14 2024 12:31:11

%S 1,1,2,3,2,4,1,2,3,2,8,12,1,2,2,5,6,6,2,3,6,6,2,2,8,3,4,2,12,2,9,8,18,

%T 2,2,6,4,12,2,3,6,4,2,6,12,8,2,6,2,1,6,8,2,2,14,4,6,2,6,2,3,20,2,12,2,

%U 2,8,14,10,18,8,6,2,2,2,12,12,19,2,6,6,20,2,2,2,8,8,2,2,8,20,12,15,2,4

%N Difference between a nontrivial prime power (A025475) and the previous prime.

%C a(n)=1 only for some powers of 2.

%F a(n) = A025475(n)-prevprime(A025475(n)) = A025475(n)-A049711(A025475(n)).

%e 78125=5^7 follows 78121, the difference is 4.

%o (Python)

%o from sympy import primepi, integer_nthroot, prevprime

%o def A060847(n):

%o def f(x): return int(n+x-sum(primepi(integer_nthroot(x,k)[0]) for k in range(2,x.bit_length())))

%o def bisection(f,kmin=0,kmax=1):

%o while f(kmax) > kmax: kmax <<= 1

%o while kmax-kmin > 1:

%o kmid = kmax+kmin>>1

%o if f(kmid) <= kmid:

%o kmax = kmid

%o else:

%o kmin = kmid

%o return kmax

%o return (a:=bisection(f,n,n))-prevprime(a) # _Chai Wah Wu_, Sep 13 2024

%Y Cf. A025475, A000961, A001597, A001694, A007917, A007918, A013632, A013633, A049711.

%K nonn

%O 1,3

%A _Labos Elemer_, May 03 2001