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

A060272 Distance from n^2 to closest prime.

Original entry on oeis.org

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

Views

Author

Labos Elemer, Mar 23 2001

Keywords

Examples

			n=1: n^2=1 has next prime 2, so a(1)=1;
n=11: n^2=121 is between primes {113,127} and closer to 127, thus a(11)=6.
		

Crossrefs

Programs

  • Maple
    seq((s-> min(nextprime(s)-s, `if`(s>2, s-prevprime(s), [][])))(n^2), n=1..256);  # edited by Alois P. Heinz, Jul 16 2017
  • Mathematica
    Table[Function[k, Min[k - #, NextPrime@ # - k] &@ If[n == 1, 0, Prime@ PrimePi@ k]][n^2], {n, 103}] (* Michael De Vlieger, Jul 15 2017 *)
    Min[#-NextPrime[#,-1],NextPrime[#]-#]&/@(Range[110]^2) (* Harvey P. Dale, Jun 26 2021 *)
  • PARI
    a(n) = if (n==1, nextprime(n^2) - n^2, min(n^2 - precprime(n^2), nextprime(n^2) - n^2)); \\ Michel Marcus, Jul 16 2017

Formula

a(n) = abs(A000290(n) - A113425(n)) = abs(A000290(n) - A113426(n)). - Reinhard Zumkeller, Oct 31 2005

A113425 Smallest prime closest to n^2.

Original entry on oeis.org

2, 3, 7, 17, 23, 37, 47, 61, 79, 101, 127, 139, 167, 197, 223, 257, 293, 317, 359, 401, 439, 487, 523, 577, 619, 677, 727, 787, 839, 907, 967, 1021, 1087, 1153, 1223, 1297, 1367, 1447, 1523, 1601, 1669, 1759, 1847, 1933, 2027, 2113, 2207, 2309, 2399, 2503
Offset: 1

Views

Author

Reinhard Zumkeller, Oct 31 2005

Keywords

Comments

A060272(n) = abs(A000290(n) - a(n));
a(n) <= A113426(n).

Programs

  • Maple
    f:= proc(n) local k,d;
      for k from 1 do
        for d in [-1,1] do
          if isprime(n^2 + k*d) then return n^2 + k*d fi
      od od
    end proc:
    map(f, [$1..100]); # Robert Israel, Mar 10 2017
  • Mathematica
    sp[n_]:=Module[{n2=n^2 ,npu,npd},npu=NextPrime[n2]; npd=NextPrime[n2,-1]; If[n2-npd<=npu-n2,npd,npu]]; sp/@Range[50]  (* Harvey P. Dale, Feb 05 2011 *)

A181758 Greatest prime closest to n^3.

Original entry on oeis.org

2, 7, 29, 67, 127, 211, 347, 509, 727, 997, 1327, 1733, 2203, 2741, 3373, 4099, 4909, 5827, 6857, 7993, 9257, 10651, 12163, 13829, 15629, 17579, 19681, 21961, 24391, 26993, 29789, 32771, 35933, 39301, 42863, 46663, 50651, 54869, 59333, 63997, 68917, 74093, 79493, 85193, 91127, 97327, 103813, 110597, 117643, 125003
Offset: 1

Views

Author

Keywords

Examples

			29 is the greatest prime closest to 3^3 = 27.
		

Crossrefs

Cf. A113426.

Programs

  • Mathematica
    f3[n_]:=Module[{n3=n^3,np1,np2},np1=NextPrime[n3,-1];np2=NextPrime[n3];If[(n3-np1)<(np2-n3),np1,np2]];
    Table[f3[i],{i,50}]
  • PARI
    a(n) = {if(n == 1, return(1)); my(n3 = n^3, gp = nextprime(n^3), lp = precprime(n^3)); if(n3 - lp < gp - n3, return(lp) , return(gp) ) } \\ David A. Corneth, May 25 2021
Showing 1-3 of 3 results.