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.

Previous Showing 11-20 of 27 results. Next

A296239 a(n) = distance from n to nearest Fibonacci number.

Original entry on oeis.org

0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 2, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 16, 15, 14, 13, 12, 11, 10, 9
Offset: 0

Views

Author

Rémy Sigrist, Dec 09 2017

Keywords

Comments

The Fibonacci numbers correspond to sequence A000045.
This sequence is analogous to:
- A051699 (distance to nearest prime),
- A053188 (distance to nearest square),
- A053646 (distance to nearest power of 2),
- A053615 (distance to nearest oblong number),
- A053616 (distance to nearest triangular number),
- A061670 (distance to nearest power),
- A074989 (distance to nearest cube),
- A081134 (distance to nearest power of 3),
The local maxima of the sequence correspond to positive terms of A004695.
a(n) = 0 iff n = A000045(k) for some k >= 0.
a(n) = 1 iff n = A061489(k) for some k > 4.
For any n >= 0, abs(a(n+1) - a(n)) <= 1.
For any n > 0, a(n) < n, and a^k(n) = 0 for some k > 0 (where a^k denotes the k-th iterate of a); k equals A105446(n) for n = 1..80 (and possibly more values).
a(n) > max(a(n-1), a(n+1)) iff n = A001076(k) for some k > 1.

Examples

			For n = 42:
- A000045(9) = 34 <= 42 <= 55 = A000045(10),
- a(42) = min(42 - 34, 55 - 42) = min(8, 13) = 8.
		

Crossrefs

Programs

  • Mathematica
    fibPi[n_] := 1 + Floor[ Log[ GoldenRatio, 1 + n*Sqrt@5]]; f[n_] := Block[{m = fibPi@ n}, Min[n - Fibonacci[m -1], Fibonacci[m] - n]]; Array[f, 81, 0] (* Robert G. Wilson v, Dec 11 2017 *)
    With[{nn=80,fibs=Fibonacci[Range[0,20]]},Table[Abs[n-Nearest[fibs,n]][[1]],{n,0,nn}]] (* Harvey P. Dale, Jul 02 2022 *)
  • PARI
    a(n) = for (i=1, oo, if (n<=fibonacci(i), return (min(n-fibonacci(i-1), fibonacci(i)-n))))

Formula

a(n) = abs(n - Fibonacci(floor(log(sqrt(20)*n)/log((1 + sqrt(5))/2)-1))). - Jon E. Schoenfield, Dec 14 2017

A079677 Distance from F(n) to closest prime, where F(n) is the n-th Fibonacci number.

Original entry on oeis.org

2, 1, 1, 0, 0, 0, 1, 0, 2, 3, 2, 0, 5, 0, 2, 3, 4, 0, 5, 4, 2, 3, 2, 0, 13, 4, 10, 11, 14, 0, 23, 4, 4, 9, 10, 14, 11, 6, 12, 3, 2, 6, 7, 0, 16, 9, 24, 0, 5, 20, 18, 23, 14, 6, 9, 12, 10, 21, 4, 30, 13, 38, 4, 7, 16, 12, 19, 36, 22, 31, 4, 32, 11, 12, 60, 7, 2, 6, 27, 12, 62, 25, 20, 0, 19, 78, 6
Offset: 0

Views

Author

Benoit Cloitre, Jan 26 2003

Keywords

Crossrefs

Programs

  • Mathematica
    Table[f = Fibonacci[n]; If[PrimeQ[f], 0, Min[f - NextPrime[f, -1], NextPrime[f] - f]], {n, 0, 100}] (* _T. D. Noe, May 02 2012 *)
  • PARI
    a(s)=min(abs(precprime(fibonacci(s))-fibonacci(s)),abs(nextprime(fibonacci(s))-fibonacci(s)))

A132470 Smallest number at distance exactly 3n from nearest prime.

Original entry on oeis.org

2, 26, 119, 532, 1339, 1342, 9569, 15704, 19633, 31424, 31427, 31430, 31433, 155960, 155963, 360698, 360701, 370312, 370315, 492170, 1357261, 1357264, 1357267, 2010802, 2010805, 4652428, 17051785, 17051788, 17051791, 17051794, 17051797, 20831416, 20831419, 20831422
Offset: 0

Views

Author

Jonathan Vos Post, Sep 03 2007

Keywords

Comments

Let f(m)= A051699(m) = exact distance from m to its closest prime (including m itself). Then a(n) = min { m : f(m) = 3n}. - R. J. Mathar, Nov 18 2007
This sequence can be derived from the record prime gap sequences A002386 and A005250. In particular, for n > 0, a(n) = A002386(k) + 3*n where k is the least index such that A005250(k) >= 3*n. - Andrew Howroyd, Jan 04 2020

Examples

			a(3)=532 where 532+3*3 is prime and all numbers below 532 have a distance smaller or larger than 3n=9 to their nearest primes and there is no prime within a distance of 8 to 532.
		

Crossrefs

Programs

  • Maple
    A051699 := proc(m) if isprime(m) then 0 ; elif m <= 2 then op(m+1,[2,1]) ; else min(nextprime(m)-m,m-prevprime(m)) ; fi ; end: A132470 := proc(n) local m ; if n = 0 then RETURN(2); else for m from 0 do if A051699(m) = 3 * n then RETURN(m) ; fi ; od: fi ; end: seq(A132470(n),n=0..18) ; # R. J. Mathar, Nov 18 2007
  • Mathematica
    terms = 34;
    gaps = Cases[Import["https://oeis.org/A002386/b002386.txt", "Table"], {, }][[;; terms, 2]];
    w[n_] := (NextPrime[gaps[[n]] + 1] - gaps[[n]])/6 // Floor;
    k = 1; a[0] = 2;
    For[n = 1, n <= terms, n++, While[w[k] < n, k++]; a[n] = gaps[[k]] + 3n];
    a /@ Range[0, terms-1] (* Jean-François Alcover, Apr 09 2020, after Andrew Howroyd *)
  • PARI
    \\ here R(gaps) wants prefix of A002386 as vector.
    aA002386(lim)={my(L=List(),q=2,g=0); forprime(p=3, lim, if(p-q>g, listput(L,q); g=p-q); q=p); Vec(L)}
    R(gaps)={my(w=vector(#gaps, n, nextprime(gaps[n]+1) - gaps[n])\6, r=vector(w[#w]+1), k=1); r[1]=2; for(n=1, w[#w], while(w[k]A002386(10^7))} \\ Andrew Howroyd, Jan 04 2020

Formula

a(n) = min {m : A051699(m) = 3n}. - R. J. Mathar, Nov 18 2007

Extensions

Corrected by Dean Hickerson, Sep 05 2007
Both this sequence and A051728 should be checked. There are two possibilities for confusion in each case. In defining f(m), does one allow or exclude m itself, in case m is a prime? In defining a(n), does one require (here) that f(m) = 3n or only that >= 3n, or (in A051728) that f(m) = 2n or only >= 2n? Probably there should be several sequences, to include all the possibilities in each case. - N. J. A. Sloane, Nov 18 2007. Added Nov 20 2007: R. J. Mathar has now clarified the definition of the present sequence.
Corrected and extended by R. J. Mathar, Nov 18 2007
Terms a(19) and beyond from Andrew Howroyd, Jan 04 2020

A163497 Numbers n with following property: let c = nearest cube to n that is different from n and let p = nearest prime to n that is different from n. Then |n-c| = |n-p|.

Original entry on oeis.org

2, 25, 28, 119, 126, 340, 345, 728, 731, 1329, 1346, 2188, 2200, 3374, 3382, 4911, 4916, 6858, 6861, 9259, 9269, 12165, 12182, 15622, 15627, 19682, 19685, 24384, 24390, 29790, 29797, 35935, 35944, 42869, 42887, 50652, 50662, 59300, 59326
Offset: 1

Views

Author

Gaurav Kumar, Jul 29 2009

Keywords

Comments

With the exception of 2 those k where A051699(k) = A074989(k) (same distance to nearest prime and to nearest cube). - R. J. Mathar, Aug 08 2009

Examples

			a(1) = 2 since 2 lies between 1 (cube) and 3 (prime);
a(2) = 28 since 28 lies between 27 (cube) and 29 (prime).
		

Crossrefs

Cf. A154840.

Programs

  • Maple
    A163497 := proc(n) option remember ; local a; if n = 1 then 2; else for a from procname(n-1)+1 do if A051699(a) = A074989(a) then return a; end if; end do ; end if; end proc: # R. J. Mathar, Nov 01 2009

Extensions

Edited by Zak Seidov, Aug 01 2009
Further edited by N. J. A. Sloane, Oct 31 2009

A301295 Smallest distance from n to a prime power (as defined in A000961).

Original entry on oeis.org

0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 2, 2, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 2, 3, 2, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 3, 2, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2
Offset: 1

Views

Author

N. J. A. Sloane, Mar 24 2018

Keywords

Crossrefs

There are four different sequences which may legitimately be called "prime powers": A000961 (p^k, k >= 0), A246655 (p^k, k >= 1), A246547 (p^k, k >= 2), A025475 (p^k, k=0 and k >= 2).
Identical to A080732 except here a(1)=0.
Cf. also A051699, A175851.

Programs

  • PARI
    A301295(n) = if(1==n,0,my(k=0);while(!isprimepower(n+k) && !isprimepower(n-k), k++); (k)); \\ Antti Karttunen, Sep 25 2018

Extensions

More terms from Antti Karttunen, Sep 25 2018

A366092 Distance from the sum of the first n primes to the nearest prime.

Original entry on oeis.org

2, 0, 0, 1, 0, 1, 0, 1, 2, 1, 2, 3, 0, 1, 0, 3, 2, 1, 2, 1, 2, 3, 4, 3, 4, 1, 2, 5, 2, 1, 4, 1, 4, 1, 2, 3, 4, 5, 2, 3, 2, 5, 2, 1, 2, 1, 2, 3, 2, 1, 2, 1, 2, 3, 2, 1, 2, 1, 10, 1, 0, 11, 2, 1, 0, 3, 2, 3, 2, 7, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5, 2, 5, 4, 3, 10, 3
Offset: 0

Views

Author

Paolo Xausa, Sep 29 2023

Keywords

Comments

Positions of zeros are given by A013916.
Positions of records are given by A366093.

Examples

			a(3) = 1 because the sum of the first 3 primes is 2 + 3 + 5 = 10, the nearest prime is 11 and 11 - 10 = 1.
		

Crossrefs

Programs

  • Mathematica
    pDist[n_]:=If[PrimeQ[n],0,Min[NextPrime[n]-n,n-NextPrime[n,-1]]];
    A366092list[nmax_]:=Map[pDist,Prepend[Accumulate[Prime[Range[nmax]]],0]];
    A366092list[100]
  • Python
    from sympy import prime, nextprime, prevprime
    def A366092(n): return min((m:=sum(prime(i) for i in range(1,n+1)))-prevprime(m+1),nextprime(m)-m) if n else 2 # Chai Wah Wu, Oct 03 2023

Formula

a(n) = A051699(A007504(n)).
a(n) = abs(A007504(n) - A366094(n)).

A336364 Rectangular array by antidiagonals: row n shows the positive integers whose distance to the nearest prime is n.

Original entry on oeis.org

2, 3, 1, 5, 4, 9, 7, 6, 15, 26, 11, 8, 21, 34, 93, 13, 10, 25, 50, 117, 118, 17, 12, 27, 56, 123, 122, 119, 19, 14, 33, 64, 143, 144, 121, 120, 23, 16, 35, 76, 145, 186, 205, 300, 531, 29, 18, 39, 86, 185, 204, 217, 324, 533, 532, 31, 20, 45, 92, 187, 206
Offset: 1

Views

Author

Clark Kimberling, Jul 19 2020

Keywords

Comments

Row 1: the primes, A000040. Every positive integer occurs exactly once, so that as a sequence, this is a permutation of the positive integers.

Examples

			Corner:
   2   3   5   7  11   13   17   19   23   29   31   37
   1   4   6   8  10   12   14   16   18   20   22   24
   9  15  21  25  27   33   35   39   45   49   51   55
  26  34  50  56  64   76   86   92   94  116  124  134
  93 117 123 143 145  185  187  203  207  215  219  245
		

Crossrefs

Programs

  • Mathematica
    a[?PrimeQ] = 0; a[n] := Min[NextPrime[n] - n, n - NextPrime[n, -1]];
    t = Table[a[n], {n, 1, 2000}]; (* A051699 *)
    r[n_] := Flatten[Position[t, n]]; u[n_, k_] := r[n][[k]];
    TableForm[Table[u[n, k], {n, 0, 15}, {k, 1, Length[r[n]]}]] (* A337364, array *)
    Table[u[n - k, k], {n, 0, 15}, {k, n, 1, -1}] // Flatten    (* A337364, sequence *)

A336365 Rectangular array by antidiagonals: row n shows the nonnegative integers whose distance to the nearest prime is n.

Original entry on oeis.org

2, 3, 1, 5, 4, 0, 7, 6, 9, 26, 11, 8, 15, 34, 93, 13, 10, 21, 50, 117, 118, 17, 12, 25, 56, 123, 122, 119, 19, 14, 27, 64, 143, 144, 121, 120, 23, 16, 33, 76, 145, 186, 205, 300, 531, 29, 18, 35, 86, 185, 204, 217, 324, 533, 532, 31, 20, 39, 92, 187, 206
Offset: 1

Views

Author

Clark Kimberling, Jul 19 2020

Keywords

Comments

Row 1: the primes, A000040.
Every nonnegative integer occurs exactly once, so that as a sequence, this is a permutation of the nonnegative integers.

Examples

			 Corner:
   2    3    5    7   11   13   17   19   23   29   31   37
   1    4    6    8   10   12   14   16   18   20   22   24
   0    9   15   21   24   27   33   35   39   45   49   51
  26   34   50   56   64   76   86   92   94  116  124  134
  93  117  123  143  145  185  187  203  207  215  219  245
		

Crossrefs

Programs

  • Mathematica
    a[?PrimeQ] = 0; a[n] := Min[NextPrime[n] - n, n - NextPrime[n, -1]];
    t = Table[a[n], {n, 0, 2000}]; (*  A051699 *)
    r[n_] := -1 + Flatten[Position[t, n]]; u[n_, k_] := r[n][[k]];
    TableForm[Table[u[n, k], {n, 0, 15}, {k, 1, Length[r[n]]}]] (* A336365, array *)
    Table[u[n - k, k], {n, 0, 15}, {k, n, 1, -1}] // Flatten  (* A336365, sequence *)

A079666 Least k such that the distance from k^2 to closest prime = n or zero if no k exists.

Original entry on oeis.org

1, 3, 8, 17, 12, 11, 18, 51, 200, 59, 238, 41, 276, 165, 104, 281, 214, 397, 348, 159, 650, 305, 778, 923, 2242, 1155, 1090, 911, 822, 1871, 1280, 1099, 1516, 3253, 2578, 5849, 3538, 693, 4010, 1937, 1284, 5095, 3212, 2011, 6268, 6331, 2160, 1943, 12470, 13443, 12836, 7405, 25428, 7115, 22596, 10873
Offset: 1

Views

Author

Benoit Cloitre, Jan 26 2003

Keywords

Comments

From Robert Israel, Jan 03 2017: (Start)
For n > 1, a(n) == n (mod 2) unless it is 0.
a(191) > 3*10^7 if it is not 0. (End)

Crossrefs

Programs

  • Maple
    N:= 100: # for a(1)..a(N)
    R[1]:= 1: count:= 1:
    for k from 3 while count < N do
    d:= min(nextprime(k^2)-k^2,k^2-prevprime(k^2));
    if d <= N and not assigned(R[d]) then R[d]:= k; count:= count+1 fi
    od:
    seq(R[i],i=1..N); # Robert Israel, Jan 03 2017
  • PARI
    a(n)=if(n<0,0,s=1; while(abs(n-min(abs(precprime(s^2)-s^2),abs(nextprime(s^2)-s^2)))>0,s++); s)

Extensions

More terms from Robert Israel, Jan 03 2017

A132860 Smallest number at distance 2n from nearest prime (variant 2).

Original entry on oeis.org

2, 0, 93, 119, 531, 897, 1339, 1341, 1343, 9569, 15703, 15705, 19633, 19635, 31425, 31427, 31429, 31431, 31433, 155959, 155961, 155963, 360697, 360699, 360701, 370311, 370313, 370315, 370317, 1349591, 1357261, 1357263, 1357265, 1357267
Offset: 1

Views

Author

R. J. Mathar, Nov 18 2007, Nov 30 2007

Keywords

Comments

Let f(m) be the distance to the nearest prime as defined in A051699(m). Then a(n) = min { m: f(m)= 2n }. A051728 uses A051700(m) to define the distance.
Note that the requirement f(m)>=2n yields the same sequence as f(m)=2n here. (Reasoning: We are essentially probing for prime gaps of size 4n or larger while increasing m. One cannot get earlier hits by relaxing the requirement from the equal to the larger-or-equal sign, because m triggers as soon as the distance to the start of the gap reaches 2n, with both definitions. This is an inherent consequence of using A051699.)

Crossrefs

Programs

  • Maple
    A051699 := proc(m) if isprime(m) then 0 ; elif m <= 2 then op(m+1,[2,1]) ; else min(nextprime(m)-m,m-prevprime(m)) ; fi ; end: a := proc(n) local m ; for m from 0 do if A051699(m) = 2 * n then RETURN(m) ; fi ; od: end: seq(a(n),n=0..18);

Formula

a(n) = min {m : A051699(m) = 2n}.
Previous Showing 11-20 of 27 results. Next