A297307 Given n, define the sequence x(1) = n, thereafter if x(i) is even set x(i+1) = x(i)/2, if x(i) is odd and divisible by 3, 5 or 7 set x(i+1) = 5*x(i) + 1, otherwise set x(i+1) = 3*x(i) + 1. Then a(n) is the smallest i>1 such that x(i) = 1, 5, or 553, or -1 if none of those numbers is ever reached.
4, 2, 6, 3, 7, 7, 22, 4, 19, 2, 10, 8, 5, 23, 19, 5, 8, 20, 16, 3, 9, 11, 17, 9, 39, 6, 12, 24, 14, 20, 78, 6, 36, 9, 15, 21, 27, 17, 34, 4, 81, 10, 39, 12, 55, 18, 76, 10, 31, 40, 10, 7, 7, 13, 46, 25, 32, 15, 28, 21, 21, 79, 37, 7, 37, 37, 23, 10, 43, 16, 74, 22
Offset: 1
Keywords
Examples
n = 1, x(1) = 1 , x(2)= 4, x(3) = 2, x(4) = 1 so a(1) = 4.
Programs
-
BASIC
For n=1 to 5000 i=1:x=n 10 i=i+1 If x-2*Int(x/2)=0 Then x=x/2:Goto 20 If x-3*Int(x/3)=0 or x-5*Int(x/5)=0 Then x=5*x+1:Goto 20 x=3*x+1 20 if x=1 or x=5 or x=553 Then Print n;i:Goto 30 Goto 10 30 Next n End
-
Mathematica
With[{a = {3, 5, 7}, b = {1, 5, 553}, nn = 10^3}, Array[Length@ NestWhileList[Function[n, Which[EvenQ@ n, n/2, And[OddQ@ n, AnyTrue[a, Divisible[n, #] &]], 5 n + 1, True, 3 n + 1]], #, FreeQ[b, #] &, {2, 1}, nn] /. k_ /; k == nn + 1 -> -1 &, 72]] (* Michael De Vlieger, Dec 31 2017 *)
Comments