cp's OEIS Frontend

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.

Showing 1-1 of 1 results.

A109313 Difference between prime factors of n-th semiprime.

Original entry on oeis.org

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, 41, 26, 6, 28, 45, 14, 51, 34, 18, 57, 10, 0, 59, 38, 40, 12, 65, 44, 69, 2, 24, 71, 26, 77, 50, 16, 81, 0, 56, 87, 58, 32, 6, 95, 64, 99, 22, 36, 101, 8, 68, 105, 38, 24, 107, 70, 4
Offset: 1

Views

Author

Zak Seidov, Jun 27 2005

Keywords

Comments

a(n)=0 iff sp(n) is a square of prime, sp(n) = n-th semiprime = A001358(n).

Examples

			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.
		

Crossrefs

Programs

  • Maple
    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
    # second Maple program:
    b:= proc(n) option remember; local k;
          if n=1 then 4
        else for k from 1+b(n-1) do if not isprime(k) and
                numtheory[bigomega](k)=2 then return k fi
             od
          fi
        end:
    a:= n-> (s-> max(s)-min(s))(numtheory[factorset](b(n))):
    seq(a(n), n=1..100);  # Alois P. Heinz, Feb 05 2017
  • Mathematica
    spQ[n_] := PrimeOmega[n] == 2; fi[n_] := FactorInteger[n];
    f[n_] := fi[n][[-1, 1]] - fi[n][[1, 1]];
    f[#] & /@ Select[Range@215, spQ] (* Zak Seidov, Oct 16 2014 *)
  • Python
    from math import isqrt
    from sympy.ntheory.primetest import is_square
    from sympy import primepi, primerange, primefactors
    def A109313(n):
        def bisection(f,kmin=0,kmax=1):
            while f(kmax) > kmax: kmax <<= 1
            kmin = kmax >> 1
            while kmax-kmin > 1:
                kmid = kmax+kmin>>1
                if f(kmid) <= kmid:
                    kmax = kmid
                else:
                    kmin = kmid
            return kmax
        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)))
        return 0 if is_square(m:=bisection(f,n,n)) else (p:=primefactors(m))[1]-p[0] # Chai Wah Wu, Apr 03 2025

Extensions

Edited by Zak Seidov, Oct 16 2014
Showing 1-1 of 1 results.