login
Number of steps needed to reach a prime when the map S(n)+M(n) is applied to n, or -1 if a prime is never reached. Here S(n) and M(N) mean the sum and the product of the digits of n in base 10.
2

%I #11 Nov 03 2019 19:48:36

%S 1,0,0,3,0,2,0,2,2,2,0,1,0,3,1,1,0,1,0,1,1,3,0,4,1,2,1,3,0,1,0,1,2,1,

%T 1,2,0,2,-1,4,0,4,0,5,1,2,0,6,-1,1,1,1,0,1,2,1,1,1,0,3,0,2,2,2,1,7,0,

%U 3,-1,1,0,1,0,-1,1,3,3,1,0,3

%N Number of steps needed to reach a prime when the map S(n)+M(n) is applied to n, or -1 if a prime is never reached. Here S(n) and M(N) mean the sum and the product of the digits of n in base 10.

%C a(n)=0 if n is a prime.

%H Robert Israel, <a href="/A171772/b171772.txt">Table of n, a(n) for n = 1..10000</a>

%e a(4)=3 because 4->8->16->13 is prime.

%e a(39)=-1 because 39 -> 39 ->39 ... never reaches a prime.

%e a(49)=-1 because 49 -> 49 ->49 ... never reaches a prime.

%e a(69)=-1 because 69 -> 69 ->69 ... never reaches a prime.

%e a(74)=-1 because 74 -> 39 ->39 ... never reaches a prime.

%e a(28)=3 because 28 ->26 ->20 ->2.

%p f:= proc(n) local L;

%p L:= convert(n,base,10);

%p convert(L,`+`)+convert(L,`*`);

%p end proc:

%p g:= proc(n) option remember; local v,w;

%p if n::prime then return 0 fi;

%p v:= f(n);

%p if v = n then return -1 fi;

%p w:= procname(v);

%p if w = -1 then -1 else w+1 fi

%p end proc:

%p map(g, [$1..100]); # _Robert Israel_, Nov 03 2019

%Y A variant of A074871.

%Y Cf. A007954, A053837, A061762.

%K base,easy,sign

%O 1,4

%A _R. J. Mathar_, Oct 12 2010