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.

A082119 Smallest positive difference between d and n/d for any divisor d of n.

Original entry on oeis.org

1, 2, 3, 4, 1, 6, 2, 8, 3, 10, 1, 12, 5, 2, 6, 16, 3, 18, 1, 4, 9, 22, 2, 24, 11, 6, 3, 28, 1, 30, 4, 8, 15, 2, 5, 36, 17, 10, 3, 40, 1, 42, 7, 4, 21, 46, 2, 48, 5, 14, 9, 52, 3, 6, 1, 16, 27, 58, 4, 60, 29, 2, 12, 8, 5, 66, 13, 20, 3, 70, 1, 72, 35, 10, 15, 4, 7, 78, 2, 24, 39, 82, 5
Offset: 2

Views

Author

Ralf Stephan, Apr 04 2003

Keywords

Comments

a(n) = A056737(n) for nonsquare n. a(p) = p-1 for prime p.

Crossrefs

Cf. A082120, A000037 (nonsquares), A056737.

Programs

  • Maple
    with(numtheory):
    a:= n-> min(seq((h-> `if`(h>0, h, NULL))(d-n/d), d=divisors(n))):
    seq(a(n), n=2..100);  # Alois P. Heinz, Nov 12 2014
  • Mathematica
    a[n_] := Min[Table[If[# > 0, #, Nothing]&[d-n/d], {d, Divisors[n]}]];
    Table[a[n], {n, 2, 100}] (* Jean-François Alcover, Jan 13 2025, after Alois P. Heinz *)
  • PARI
    a(n) = my(v=divisors(n), r=sqrt(n), t=0); for(k=1, length(v), if(v[k]>=r, t=k; break)); if(v[t]^2==n, u=t, u=t-1);  if(v[t]-v[u]<1, u=u-1; t=t+1); v[t]-v[u];