This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A109313 #36 Apr 22 2025 04:00:40 %S A109313 0,1,0,3,5,2,4,9,0,11,8,15,2,17,10,21,0,14,6,16,27,29,8,20,35,4,39,12, %T A109313 41,26,6,28,45,14,51,34,18,57,10,0,59,38,40,12,65,44,69,2,24,71,26,77, %U A109313 50,16,81,0,56,87,58,32,6,95,64,99,22,36,101,8,68,105,38,24,107,70,4 %N A109313 Difference between prime factors of n-th semiprime. %C A109313 a(n)=0 iff sp(n) is a square of prime, sp(n) = n-th semiprime = A001358(n). %H A109313 Alois P. Heinz, <a href="/A109313/b109313.txt">Table of n, a(n) for n = 1..20000</a> (first 1000 terms from Zak Seidov) %e A109313 a(1)=0 because sp(1)=4=2*2 and 2-2=0; a(2)=1 because sp(2)=6=2*3 and 3-2=1; sp(n)=n-th semiprime. %p A109313 with(numtheory): a:=proc(n) if bigomega(n)=2 and nops(factorset(n))=2 then factorset(n)[2]-factorset(n)[1] elif bigomega(n)=2 then 0 else fi end: seq(a(n),n=1..225); # _Emeric Deutsch_ %p A109313 # second Maple program: %p A109313 b:= proc(n) option remember; local k; %p A109313 if n=1 then 4 %p A109313 else for k from 1+b(n-1) do if not isprime(k) and %p A109313 numtheory[bigomega](k)=2 then return k fi %p A109313 od %p A109313 fi %p A109313 end: %p A109313 a:= n-> (s-> max(s)-min(s))(numtheory[factorset](b(n))): %p A109313 seq(a(n), n=1..100); # _Alois P. Heinz_, Feb 05 2017 %t A109313 spQ[n_] := PrimeOmega[n] == 2; fi[n_] := FactorInteger[n]; %t A109313 f[n_] := fi[n][[-1, 1]] - fi[n][[1, 1]]; %t A109313 f[#] & /@ Select[Range@215, spQ] (* _Zak Seidov_, Oct 16 2014 *) %o A109313 (Python) %o A109313 from math import isqrt %o A109313 from sympy.ntheory.primetest import is_square %o A109313 from sympy import primepi, primerange, primefactors %o A109313 def A109313(n): %o A109313 def bisection(f,kmin=0,kmax=1): %o A109313 while f(kmax) > kmax: kmax <<= 1 %o A109313 kmin = kmax >> 1 %o A109313 while kmax-kmin > 1: %o A109313 kmid = kmax+kmin>>1 %o A109313 if f(kmid) <= kmid: %o A109313 kmax = kmid %o A109313 else: %o A109313 kmin = kmid %o A109313 return kmax %o A109313 def f(x): return int(n+x+((t:=primepi(s:=isqrt(x)))*(t-1)>>1)-sum(primepi(x//p) for p in primerange(s+1))) %o A109313 return 0 if is_square(m:=bisection(f,n,n)) else (p:=primefactors(m))[1]-p[0] # _Chai Wah Wu_, Apr 03 2025 %Y A109313 Cf. A001358, A068318, A178313. %K A109313 nonn %O A109313 1,4 %A A109313 _Zak Seidov_, Jun 27 2005 %E A109313 Edited by _Zak Seidov_, Oct 16 2014