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.

User: Bob Andriesse

Bob Andriesse's wiki page.

Bob Andriesse has authored 11 sequences. Here are the ten most recent ones:

A368958 Number of permutations of [n] where each pair of adjacent elements is coprime and does not differ by a prime.

Original entry on oeis.org

1, 1, 2, 2, 2, 10, 4, 28, 6, 42, 40, 348, 42, 1060, 226, 998, 886, 21660, 690, 57696, 4344, 26660, 22404, 1091902, 12142, 1770008
Offset: 0

Author

Bob Andriesse, Jan 10 2024

Keywords

Comments

The number of Hamiltonian paths in a graph of which the nodes represent the numbers (1,2,3,...,n) and the edges connect each pair of nodes that are coprime and do not differ by a prime.

Examples

			a(5) = 10: 15432, 21543, 23451, 32154, 34512, 43215, 45123, 51234, 54321, 12345.
a(6) = 4: 432156, 651234, 654321, 123456.
		

Crossrefs

Programs

  • Mathematica
    a[n_] := a[n] = Module[{b = 0, ps}, ps = Permutations[Range[n]]; Do[If[Module[{d}, AllTrue[Partition[pe, 2, 1], (d = Abs[#[[2]] - #[[1]]]; ! PrimeQ[d] && CoprimeQ[#[[1]], #[[2]]]) &]], b++], {pe, ps}]; b];
    Table[a[n], {n, 0, 8}] (* Robert P. P. McKone, Jan 12 2024 *)
  • PARI
    okperm(perm) = {for(k=1, #perm-1, if((isprime(abs(perm[k]-perm[k+1]))), return(0)); if(!(gcd(perm[k], perm[k+1])==1), return(0));); return(1);}
    a(n) = {my(nbok = 0); for (j=1, n!, perm = numtoperm(n,j); if(okperm(perm), nbok++);); return(nbok); }
    
  • Python
    from math import gcd
    from sympy import isprime
    def A368958(n):
        if n<=1 : return 1
        clist = tuple({j for j in range(1,n+1) if j!=i and gcd(i,j)==1 and not isprime(abs(i-j))} for i in range(1,n+1))
        def f(p,q):
            if (l:=len(p))==n-1: yield len(clist[q]-p)
            for d in clist[q]-p if l else set(range(1,n+1))-p:
                yield from f(p|{d},d-1)
        return sum(f(set(),0)) # Chai Wah Wu, Jan 19 2024

Extensions

a(14)-a(25) from Alois P. Heinz, Jan 11 2024

A367704 Number of permutations of [n] where each pair of adjacent elements differs by a prime.

Original entry on oeis.org

1, 1, 0, 0, 2, 10, 32, 96, 448, 1968, 7320, 21516, 118938, 662742, 4556360, 26950038, 155388246, 756995286, 5730299976, 38809702892, 337875402936, 2593543573702, 20560179519176, 138677553274430, 1337517942958934, 11083936316867572, 94288296012340842
Offset: 0

Author

Bob Andriesse, Nov 27 2023

Keywords

Comments

This sequence was inspired by A103839 and the PARI program is a modified version of the one in A103839.
The number of Hamiltonian paths in a graph of which the nodes represent the numbers (1,2,3,...,n) and the edges connect each pair of nodes that differ by a prime.
A076220, A103839 and this sequence are closely related, but their combined graph in the link shows an interesting difference, notably between this sequence and the two others. - Bob Andriesse, Dec 03 2023

Examples

			a(4) = 2: 2413, 3142.
a(5) = 10: 13524, 14253, 24135, 25314, 31425, 35241, 41352, 42531, 52413, 53142.
		

Crossrefs

Programs

  • PARI
    okperm(perm) = {for (k=1, #perm -1, if (! isprime(abs(perm[k]-perm[k+1])),  return (0));  ); return (1); }
    a(n) = {nbok = 0; for (j=1, n!, perm = numtoperm(n, j); if (okperm(perm), nbok++); ); return (nbok); }

Extensions

a(14)-a(22) from Alois P. Heinz, Nov 27 2023
a(23)-a(26) from Martin Ehrenstein, Dec 03 2023

A365249 Composite numbers k for which A214749(k) = (k-1)/2.

Original entry on oeis.org

25, 85, 121, 133, 145, 187, 205, 217, 221, 253, 301, 325, 361, 385, 403, 437, 445, 451, 481, 505, 529, 533, 553, 565, 625, 667, 697, 721, 745, 793, 817, 841, 865, 893, 913, 925, 973, 985, 1003, 1027, 1037, 1045, 1057, 1073, 1081, 1141, 1157, 1165, 1207, 1225
Offset: 1

Author

Bob Andriesse, Aug 28 2023

Keywords

Comments

As can be seen from A214749, for most odd composites k the smallest value of m that satisfies k-m | k^2+m is smaller than (k-1)/2. This sequence lists the exceptions. All the odd primes appear to satisfy A214749(p) = (p-1)/2.

Crossrefs

Programs

  • PARI
    f(n) = my(m=1); while((n^2+m) % (n-m), m++); m; \\ A214749
    lista(nn) = my(list=List()); forcomposite(c=1, nn, if (f(c) == (c-1)/2, listput(list, c))); Vec(list); \\ Michel Marcus, Sep 04 2023
  • Python
    from sympy import isprime
    a=[]
    for n in range(3,1000):
      for m in range(1,(n-1)//2+1):
       if (n**2+m)%(n-m)==0:
        if m==(n-1)/2 and not isprime(n):
         a.append(n)
        break
    print(a)
    
  • Python
    from itertools import count, islice
    from sympy import isprime
    from sympy.abc import x, y
    from sympy.solvers.diophantine.diophantine import diop_quadratic
    def A365249_gen(startvalue=3): # generator of terms >= startvalue
        return filter(lambda n:not isprime(n) and min(int(x) for x,y in diop_quadratic(n*(n-y)+x*(y+1)) if x>0)==n-1>>1, count(max(startvalue+startvalue&1^1,3),2))
    A365249_list = list(islice(A365249_gen(),30)) # Chai Wah Wu, Oct 06 2023
    

A365248 Composite numbers k that are not a prime minus one, for which A214749(k) = k/2.

Original entry on oeis.org

34, 94, 118, 142, 202, 214, 246, 274, 298, 334, 394, 402, 436, 454, 514, 526, 538, 622, 628, 634, 694, 706, 712, 754, 766, 778, 802, 814, 892, 898, 922, 934, 942, 958, 1002, 1006, 1042, 1054, 1114, 1126, 1132, 1138, 1146, 1158, 1174, 1198, 1234, 1246, 1270
Offset: 1

Author

Bob Andriesse, Aug 28 2023

Keywords

Comments

As can be seen from A214749, for most composites k that are not a prime minus one, the smallest value of m that satisfies k-m | k^2+m is smaller than k/2. This sequence lists the exceptions.

Crossrefs

Programs

  • PARI
    f(n) = my(m=1); while((n^2+m) % (n-m), m++); m; \\ A214749
    lista(nn) = my(list=List()); forcomposite(c=1, nn, if ((f(c) == c/2) && !isprime(c+1), listput(list, c))); Vec(list);  \\ Michel Marcus, Sep 08 2023
  • Python
    from sympy import isprime
    a=[]
    for n in range(2,1000):
      for m in range(1,n//2+1):
       if (n**2+m)%(n-m)==0:
        if m==n/2 and not isprime(n+1):
         a.append(n)
        break
    print(a)
    
  • Python
    from itertools import count, islice
    from sympy import isprime
    from sympy.abc import x, y
    from sympy.solvers.diophantine.diophantine import diop_quadratic
    def A365248_gen(startvalue=2): # generator of terms >= startvalue
        return filter(lambda n:not isprime(n+1) and min(int(x) for x,y in diop_quadratic(n*(n-y)+x*(y+1)) if x>0)==n>>1, count(max(startvalue+startvalue&1,2),2))
    A365248_list = list(islice(A365248_gen(),30)) # Chai Wah Wu, Oct 06 2023
    

A356465 The number of unit squares enclosed by the rectangular spiral of which the n-th side has length prime(n).

Original entry on oeis.org

0, 2, 6, 12, 27, 59, 113, 179, 257, 359, 497, 747, 963, 1227, 1577, 1799, 2081, 2611, 3223, 3663, 4167, 4817, 5231, 5847, 6657, 7527, 8801, 9869, 10439, 11057, 11699, 12425, 14675, 16817, 18027, 19139, 20855, 22595, 23803, 25711, 27321, 29011, 31063, 32495
Offset: 0

Author

Bob Andriesse, Aug 08 2022

Keywords

Comments

The pictures in the links show how the spiral is constructed. The first segment is the small black rectangle in the center, of which the left lower corner is at the origin (0,0). It represents prime(1) = 2 (its width) and is given a height of one. The first part of the boundary of the spiral is the line between (0,0) and (2,0). Prime(2) = 3 yields the next part of the boundary, the line connecting (2,0) and (2,3). The next primes determine how many unit steps the boundary of the spiral goes left, down, right, up, etc.

Crossrefs

Cf. A000040.

Programs

  • Mathematica
    a[4]:=27; a[n_]:=a[n]=a[n-1]+(Prime[n]-Prime[n-2]+Prime[n-4])(Prime[n-1]-Prime[n-3]); Join[{0,2,6,12,27},Table[a[n],{n,5,45}]] (* Stefano Spezia, Aug 09 2022 *)
  • Python
    from sympy import prime as p
    a = [0,2,6,12,27] #first 4 area values
    area = 27
    for n in range(5,44+1):
      darea = (p(n) - p(n-2) + p(n-4)) * (p(n-1) - p(n-3))
      area += darea
      a.append(area)
    print('a(n)=',a)

Formula

a(n) = a(n-1) +(prime(n) - prime(n-2) + prime(n-4))*(prime(n-1) - prime(n-3)) for n > 4.

A339247 The primes that yield twice a prime when each bit of their binary expansion is inverted.

Original entry on oeis.org

11, 17, 37, 41, 53, 59, 89, 101, 113, 137, 149, 173, 181, 193, 197, 229, 233, 241, 251, 257, 293, 317, 353, 389, 449, 521, 541, 557, 569, 577, 601, 641, 661, 677, 709, 761, 769, 797, 809, 821, 829, 857, 877, 881, 929, 937
Offset: 1

Author

Bob Andriesse, Nov 28 2020

Keywords

Comments

Primes p such that A035327(p)/2 is prime.
Obviously the resulting prime is smaller than the starting prime.
Conjecture: Each of the primes can be created by applying this transformation T(p) to at least one other prime. T(11)=2, T(549755813881)=3, T(53)=5, T(17)=7, T(41)=11.

Examples

			a(1) = 11 = 1011_2 —inv-> 100_2 = 4 = 2 * 2.
a(2) = 17 = 10001_2 -inv-> 1110_2 = 14 = 2 * 7.
a(3) = 37 = 100101_2 -inv-> 11010_2 = 26 = 2 * 13.
		

Crossrefs

Programs

  • Maple
    filter:= proc(n) isprime(n) and isprime((2^(1+ilog2(n))-1-n)/2) end proc:
    select(filter, [seq(i,i=3..1000,2)]); # Robert Israel, Jun 27 2023
  • Mathematica
    Select[Range[1000], And @@ PrimeQ[{#, (2^Ceiling @ Log2[#] - # - 1)/2}] &] (* Amiram Eldar, Dec 01 2020 *)
  • PARI
    isok(p) = if ((p>2) && isprime(p), isprime(fromdigits(apply(x->1-x, binary(p)), 2)/2)); \\ Michel Marcus, Dec 01 2020
  • Python
    from sympy import isprime
    from sympy import prime
    for i in range(1,201):
      j=prime(i)
      xor=2**len(bin(j).strip('0b'))-1
      p=(j^xor)//2
      if isprime(p):
       print(j,end=', ')
    

A339268 The smallest prime that becomes 2 * prime(n), when all the bits in its binary expansion are inverted, or -1 if no such prime exists.

Original entry on oeis.org

11, 549755813881, 53, 17, 41, 37, 16349, 89, 977, 197, 193, 181, 173, 937, 929, 149, 137, 389, 1913, 881, 877, 353, 857, 3917, 317, 821, 3889, 809, 293, 797, 257, 761, 3821, 65257, 3797, 3793, 709, 1721, 3761, 677, 1048217, 661, 641, 3709, 3701, 3697, 601, 577
Offset: 1

Author

Bob Andriesse, Nov 29 2020

Keywords

Comments

Conjecture: a(n) > 0 for all n.
a(6705), for prime(6705) = 67289, is either -1 or greater than (2^62500 - 1) * 262144 + 127565, which has 18820 digits. - Michael S. Branicky, Dec 05 2020

Examples

			a(1) = 11, because 11 = 1011_2 -inv-> 0100_2 = 4 = 2 * 2.
a(2) = 549755813881, because 549755813881 = 111111111111111111111111111111111111001_2 -inv-> 110_2 = 6 = 2 * 3. No smaller prime generates 3.
a(3) = 53, because 53 = 110101_2 -inv-> 001010_2 = 10 = 2 * 5.
		

Crossrefs

Programs

  • Mathematica
    a[n_] := Module[{q = 2*Prime[n], m, r}, m = 2^Ceiling@Log2[q]; r = m - q - 1; While[r < q || ! PrimeQ[r], r += m; m *= 2]; r]; Array[a, 48] (* Amiram Eldar, Dec 04 2020 *)
  • PARI
    a(n) = {my(b = apply(x->1-x, binary(2*prime(n))), e=#b, q=fromdigits(b, 2)+2^e); while (!isprime(q), e++; q+=2^e; q); q;} \\ Michel Marcus, Dec 04 2020
  • Python
    from sympy import isprime
    from sympy import prime
    for i in range(1,50):
      d=2*prime(i)
      l=len(bin(d).lstrip('0b'))
      xor=2**l-1
      p=d^xor+2**l
      while not isprime(p):
       l+=1
       p+=2**l
      print(p,end=', ')
    

A309655 The smallest possible nonnegative difference between the sum of the first n primes (A007504) and the sum of any number of the directly following and consecutive primes.

Original entry on oeis.org

0, 2, 0, 3, 6, 15, 5, 16, 25, 3, 20, 39, 13, 36, 61, 17, 50, 6, 39, 76, 14, 53, 102, 28, 75, 132, 46, 101, 158, 46, 99, 174, 64, 145, 27, 114, 193, 51, 144, 239, 93, 194, 24, 135, 244, 74, 179, 294, 116, 253, 43, 162, 291, 61, 196, 337, 101, 250, 395, 139, 282, 427, 149, 324
Offset: 0

Author

Bob Andriesse, Aug 11 2019

Keywords

Comments

Conjecture: a(0)=0, a(2)=0 and a(532)=0 are the only zeros in the sequence. a(n) has been computed for primes < 10^10. - Bob Andriesse, Oct 07 2020

Examples

			a(2) = 2 + 3 - 5 = 0;
a(3) = 2 + 3 + 5 - 7 = 3;
a(6) = 2 + 3 + 5 + 7 + 11 + 13 - (17 + 19) = 5.
a(532)=0 because A007504(733) = 2*A007504(532).
		

Crossrefs

Programs

  • Python
    #Lists a(1)...a(100)
    from sympy import prime
    sumP=0
    for i in range(1,101):
      sumP+=prime(i)
      j=i+1
      diff=sumP
      while diff-prime(j) >=0:
       diff-=prime(j)
       j+=1
      print(diff, end=', ')
    
  • Python
    from itertools import islice
    from gmpy2 import next_prime
    def a309655_gen():
        lower_prime = upper_prime = difference = 0
        while True:
            while difference >= 0:
                upper_prime = next_prime(upper_prime)
                if difference < upper_prime:
                    yield int(difference)
                difference -= upper_prime
            lower_prime = next_prime(lower_prime)
            difference += 2 * lower_prime
    print(list(islice(a309655_gen(), 64))) # David Radcliffe, Jun 10 2025

A309714 The smallest possible nonnegative difference between the sum of the first n positive integers (A000217) and the sum of any number of the directly following and consecutive integers.

Original entry on oeis.org

1, 0, 2, 5, 2, 6, 1, 6, 12, 5, 12, 3, 11, 0, 9, 19, 6, 17, 2, 14, 27, 10, 24, 5, 20, 36, 15, 32, 9, 27, 2, 21, 41, 14, 35, 6, 28, 51, 20, 44, 11, 36, 1, 27, 54, 17, 45, 6, 35, 65, 24, 55, 12, 44, 77, 32, 66, 19, 54, 5, 41, 78, 27, 65, 12, 51, 91, 36, 77, 20, 62
Offset: 1

Author

Bob Andriesse, Aug 13 2019

Keywords

Comments

a(n) = 0 if a positive integer m exists, such that m * (m + 1) = 2 * n * (n + 1). Let k = m - n, then n = (2 * k - 1 + sqrt(8 * k^2 + 1)) / 2. All k for which 8 * k^2 + 1 is a perfect square (A001109) yield a value for n for which a(n) = 0.
a(A053141(n)) = 0 for all n.

Examples

			a(2) = 1 + 2 - 3 = 0;
a(3) = 1 + 2 + 3 - 4 = 2;
a(7) = 1 + 2 + 3 + 4 + 5 + 6 + 7 - (8 + 9 + 10) = 1.
a(A053141(2)) = a(14) = 0, because A000217(20) = 2 * A000217(14).
		

Crossrefs

Programs

  • PARI
    a(n) = {my(t=n*(n+1)/2, k = n+1); while(t >= k, t -= k; k++); t;} \\ Michel Marcus, Aug 16 2019

A308416 Values of m for which 2*p + m cannot be a square when p is a prime.

Original entry on oeis.org

1, 4, 8, 9, 13, 16, 17, 20, 24, 25, 28, 29, 33, 36, 37, 40, 41, 44, 48, 49, 52, 53, 56, 57, 61, 64, 65, 68, 69, 72, 73, 76, 80, 81, 84, 85, 88, 89, 92, 93, 97, 100, 101, 104, 105, 108, 109, 112, 113, 116, 120, 121, 124, 125, 128, 129, 132, 133, 136, 137, 141, 144, 145, 148, 149
Offset: 1

Author

Bob Andriesse, May 25 2019

Keywords

Comments

m = i^2 + 4*j is a term for i > 0, 0 <= j < i. Proof: If p = 2, then i^2 < 2*p + m < (i+2)^2. Therefore (i+1)^2 = 4 + i^2 + 4*j, which leads to a contradiction. If p > 2 is such that 2*p + i^2 + 4*j = k^2, then k + i and k - i are both even numbers. Therefore 4 | 2*p + 4*j, which is also a contradiction.
The terms of this sequence can be obtained by starting with A042948 (numbers congruent to 0 or 1 mod 4) and deleting the terms of A028347 (n^2 - 4).

Crossrefs

Programs

  • Python
    a=[]
    a.append(0) #Offset starts at 1
    iMax=15 #Example value
    for i in range(1,iMax+1):
      for j in range(0,i):
       m=i*i+j*4
       a.append(m)
    a.sort()

Formula

Conjecture: for k > 0 and 1 <= j <= k, a(2k^2-2j+1) = 4k^2+4k-4j-3, a(2k^2-2j+2) = 4k^2+4k-4j, a(2k^2+2k-2j+1) = 4k^2+8k-4j, a(2k^2+2k-2j+2) = 4k^2+8k-4j+1. - Jinyuan Wang, Jul 23 2019