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-2 of 2 results.

A327467 a(n) = smallest k such that n can be expressed as a signed sum of the first k primes.

Original entry on oeis.org

3, 2, 1, 4, 3, 2, 3, 4, 5, 6, 3, 4, 5, 4, 5, 6, 7, 4, 5, 6, 7, 6, 5, 6, 5, 6, 7, 6, 5, 8, 7, 6, 7, 8, 7, 6, 7, 6, 7, 8, 7, 6, 7, 8, 7, 8, 9, 8, 7, 8, 9, 8, 7, 8, 7, 8, 9, 8, 7, 8, 9, 8, 9, 8, 9, 10, 9, 8, 9, 10, 9, 8, 9, 8, 9, 10, 9, 8, 9, 10, 9, 10, 9, 10, 9, 10
Offset: 0

Views

Author

N. J. A. Sloane, Sep 29 2019

Keywords

Comments

Smallest k such that n = +- p_1 +- p_2 +- p_3 +- ... +- p_k for a suitable choice of signs, where p_i = i-th prime.

Examples

			Illustration of initial terms:
0  =   2 + 3 - 5
1  = - 2 + 3
2  =   2
3  = - 2 + 3 - 5 + 7
4  =   2 - 3 + 5
5  =   2 + 3
6  = - 2 + 3 + 5
7  =   2 + 3 - 5 + 7
8  =   2 - 3 + 5 - 7 + 11
9  =   2 - 3 + 5 + 7 + 11 - 13
10 =   2 + 3 + 5
(for more examples see links)
		

References

  • Allan C. Wechsler, Posting to Sequence Fans Mailing List, circa Aug 29 2019.

Crossrefs

Programs

  • Mathematica
    (* 1001 terms *) sgn[w_] := Union@ Abs[Total /@ (w # & /@ Tuples[{1, -1}, Length@w])]; set[n_] := Block[{h = Floor[n/2], p = Prime@ Range@ n, x, y}, x = sgn[Take[p, h]]; y = sgn[Take[p, h - n]]; Union@ Flatten@ Table[{e + f, Abs[e - f]}, {e, x}, {f, y}]]; T = {}; L = 0 Range[1001]; k = 0; While[Length[T] < 1001, k++; s = Select[set[k], # <= 1000 && ! MemberQ[T, #] &]; Do[L[[e + 1]] = k, {e, s}]; T = Union[T, s]]; L (* Giovanni Resta, Sep 30 2019 *)
  • Python
    from sympy import sieve as prime
    def A327467(n):
        array, np, k = [2], 1, 1
        while n not in array:
            temp = []; np += 1; k += 1
            for item in array:
                temp.append(item + prime[k])
                temp.append(abs(item - prime[k]))
            array = set(temp)
        return np
    print([A327467(n) for n in range(0, 100)]) # Karl-Heinz Hofmann, May 30 2023

Formula

a(A007504(n)) = n for n > 0. - Seiichi Manyama, Sep 30 2019
Conjecture. Let k be the smallest integer satisfying n<=A007504(k). If n=9 or 16, a(n)=k+3 (so a(9)=6, a(16)=7), else if A007504(k)-n is odd, a(n)=k+1. If A007504(k)-n=2 or 8 or 12, a(n)=k+2, otherwise a(n)=k. - Kei Fujimoto, Sep 24 2021

Extensions

More terms from Giovanni Resta, Sep 30 2019

A197702 Smallest positive integer k such that n = +-1 +-3 +-... +-(2k-1) for some choice of +'s and -'s.

Original entry on oeis.org

1, 2, 3, 2, 5, 4, 3, 4, 3, 4, 5, 6, 5, 4, 5, 4, 5, 6, 5, 6, 7, 6, 5, 6, 5, 6, 7, 6, 7, 6, 7, 8, 7, 6, 7, 6, 7, 8, 7, 8, 7, 8, 7, 8, 9, 8, 7, 8, 7, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 10, 9, 8, 9, 8, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 9, 10, 11, 10, 9, 10, 9, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 12, 11, 10, 11, 10
Offset: 1

Views

Author

John W. Layman, Oct 18 2011

Keywords

Comments

Conjecture. Let SO(k) be the sum of the first k odd positive integers. Then a(n)=k if n=SO(k). Otherwise, choose k so that SO(k-1)

Examples

			The sum of 3 terms 1 - 3 + 5 gives 3, but none of the 2-term sums 1+3, 1-3, -1+3, -1-3 gives 3, so a(3)=3.
		

Crossrefs

Cf. A140358.

Programs

  • Maple
    b:= proc(n, i) option remember; (n=0 and i=0) or
          abs(n)<=i^2 and (b(n-2*i+1, i-1) or b(n+2*i-1, i-1))
        end:
    a:= proc(n) local k;
          for k from floor(sqrt(n)) while not b(n, k) do od; k
        end:
    seq(a(n), n=1..100); # Alois P. Heinz, Oct 19 2011
  • Mathematica
    b[n_, i_] := b[n, i] = (n==0 && i==0) || Abs[n] <= i^2 && (b[n-2i+1, i-1] || b[n+2i-1, i-1]);
    a[n_] := Module[{k}, For[k = Floor[Sqrt[n]], !b[n, k], k++]; k];
    Array[a, 100] (* Jean-François Alcover, Nov 12 2020, after Alois P. Heinz *)
Showing 1-2 of 2 results.