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

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

A301573 Distance to nearest perfect power n^k, k>=2 (A001597).

Original entry on oeis.org

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

Views

Author

Rémy Sigrist and Altug Alkan, Mar 23 2018

Keywords

Comments

Differs from A061670 at n=36.
Let b(n) be the smallest t such that a(t) = n. Initial values of b(n) are 1, 0, 6, 12, 20, 41, 42, 56, 72, 90, 110, 155, 156, 182, 270, 271, 272, 306, 379, ...
The b(n) sequence determines the positions of certain humps of a(n) sequence. See scatterplot of this sequence in order to observe general structure of a(n).
b(n) is A366928(n). - Dmitry Kamenetsky, Oct 28 2023

Examples

			a(20) = a(21) = 4 because 16 is the nearest perfect power to 20 and 25 is the nearest perfect power to 21 (20 - 16 = 25 - 21 = 4).
a(36) = 0 because 36 is a square.
		

Crossrefs

Programs

  • PARI
    isA001597(n) = {ispower(n) || n==1}
    a(n) = {my(k=0); while(!isA001597(n+k) && !isA001597(n-k), k++); k;}
    
  • Python
    from itertools import count
    from sympy import perfect_power
    def A301573(n): return next(k for k in count(0) if perfect_power(n+k) or perfect_power(n-k) or n-k==1 or n+k==1) # Chai Wah Wu, Nov 12 2023

Formula

a(n) = 0 iff n belongs to A001597.

A301630 a(n) = distance of n-th prime to nearest prime power p^k, k=0 and k >= 2 (A025475).

Original entry on oeis.org

1, 1, 1, 1, 2, 3, 1, 3, 2, 2, 1, 5, 8, 6, 2, 4, 5, 3, 3, 7, 8, 2, 2, 8, 16, 20, 18, 14, 12, 8, 1, 3, 9, 11, 20, 18, 12, 6, 2, 4, 10, 12, 22, 24, 28, 30, 32, 20, 16, 14, 10, 4, 2, 5, 1, 7, 13, 15, 12, 8, 6, 4, 18, 22, 24, 26, 12, 6, 4, 6, 8, 2, 6, 12, 18, 22, 28, 36, 40, 48, 58, 60, 70, 72, 73, 69, 63, 55
Offset: 1

Views

Author

Altug Alkan, Mar 24 2018

Keywords

Examples

			a(9) = a(10) = 2 because 5^2 is the nearest prime power (A025475) to prime(9) = 23 and 3^3 is the nearest prime power (A025475) to prime(10) = 29.
		

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).

Programs

  • Maple
    Primes:= select(isprime, [2,seq(i,i=3..1000,2)]):
    Ppows:= sort([1,seq(seq(p^j, j=2..floor(log[p](1000))),p=Primes)]):
    for n from 1 while Primes[n] < Ppows[-1] do
      i:= ListTools:-BinaryPlace(Ppows,Primes[n]);
      A[n]:= min(Primes[n]-Ppows[i],Ppows[i+1]-Primes[n])
    od:
    seq(A[i],i=1..n-1); # Robert Israel, Mar 26 2018
  • PARI
    isA025475(n) = {isprimepower(n) && !isprime(n) || n==1}
    a(n) = {my(k=1, p=prime(n)); while(!isA025475(p+k) && !isA025475(p-k), k++); k; }

Formula

a(n) = A061670(A000040(n)).

A301296 Smallest distance from n to a prime power (as defined in A246547).

Original entry on oeis.org

3, 2, 1, 0, 1, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 1, 0, 1, 2, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4
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).
Showing 1-4 of 4 results.