OFFSET
2,1
COMMENTS
A modified version of the halving and tripling Collatz algorithm, which stops as soon as the starting number becomes a prime (instead of stopping when the starting number reaches 1).
The plot of this sequence "completes" or "fills" the lower (empty) part of plot of A270570 and evolves in a similar fashion.
LINKS
Alessandro Polcini, Table of n, a(n) for n = 2..10000 (a(2024) corrected by Michel Marcus, Jun 14 2022)
FORMULA
a(n) <= A087272(n). - Rémy Sigrist, Oct 08 2018
EXAMPLE
a(4) is 2 because 4/2 = 2 and 2 is prime.
a(6) is 3 because 6/2 = 3 and 3 is prime.
a(15) is 23 because 15*3 + 1 = 46; 46/2 = 23 and 23 is prime.
a(18) is 7 because 18/2 = 9; 9*3 + 1 = 28; 28/2 = 14; 14/2 = 7 and 7 is prime.
MATHEMATICA
Array[NestWhile[If[EvenQ@ #, #/2, 3 # + 1] &, #, ! PrimeQ@ # &] &, 86, 2] (* Michael De Vlieger, Nov 07 2018 *)
PROG
(Java) int collatzPrime(int i) {
while(!BigInteger.valueOf(i).isProbablePrime(10) && i > 1) {
if(i % 2 == 0)
i /= 2;
else
i = 3 * i + 1;
}
return i;
}
(PARI) a(n) = {while (!isprime(n), if (n % 2, n = 3*n+1, n = n/2); ); n; } \\ Michel Marcus, Oct 28 2018
CROSSREFS
KEYWORD
nonn
AUTHOR
Alessandro Polcini, Oct 03 2018
STATUS
approved