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.
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
Examples
a(4)=6 because 4 -> 20 -> 24 -> 44 -> 76 -> 161 -> 199, takes 6 steps to reach a prime.
Links
- Robert Israel, Table of n, a(n) for n = 1..10000
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
Comments