OFFSET
1,4
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
LINKS
Robert Israel, Table of n, a(n) for n = 1..10000
EXAMPLE
a(4)=6 because 4 -> 20 -> 24 -> 44 -> 76 -> 161 -> 199, takes 6 steps to reach a prime.
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 *)
PROG
(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
CROSSREFS
KEYWORD
AUTHOR
Jason Earls, Jun 13 2004
STATUS
approved