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.

A094830 Start with x = n, repeatedly replace x with x + sum of squares of digits of x until you reach a prime; sequence gives number of steps.

Original entry on oeis.org

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

Views

Author

Jason Earls, Jun 13 2004

Keywords

Comments

It is currently not known if this sequence is well defined, i.e. if for all n>=1 there exists an integer v such that a(n) = v. If the sequence is not well defined then the given programs are incorrect as they will get stuck in an infinite loop for some integers. - Peter Luschny, Oct 28 2016

Examples

			a(4)=6 because 4 -> 20 -> 24 -> 44 -> 76 -> 161 -> 199, takes 6 steps to reach a prime.
		

Crossrefs

Programs

  • Maple
    f:= proc(n) local x,k;
    x:= n;
    for k from 0 do
      if isprime(x) then return k fi;
      x:= x + add(t^2, t = convert(x,base,10))
    od;
    end proc:
    map(f, [$1..100]); # Robert Israel, Oct 27 2016
  • Mathematica
    p[n_]:=Length[NestWhileList[#+Total[IntegerDigits[#]^2]&,n, !PrimeQ[ #]&]]-1; Array[p,100] (* Harvey P. Dale, Dec 03 2011 *)
  • PARI
    a(n) = my(k=0); while(!isprime(n),d=digits(n); n+=vecsum(vector(#d,i,d[i]^2)); k++) ;k \\ David A. Corneth, Oct 27 2016