A320028 a(n) is the first prime encountered when running the Collatz algorithm (halving and tripling steps) on the number n.
2, 3, 2, 5, 3, 7, 2, 7, 5, 11, 3, 13, 7, 23, 2, 17, 7, 19, 5, 2, 11, 23, 3, 19, 13, 41, 7, 29, 23, 31, 2, 19, 17, 53, 7, 37, 19, 59, 5, 41, 2, 43, 11, 17, 23, 47, 3, 37, 19, 29, 13, 53, 41, 83, 7, 43, 29, 59, 23, 61, 31, 137, 2, 37, 19, 67, 17, 13, 53, 71, 7, 73, 37, 113, 19, 29, 59, 79, 5, 61, 41, 83, 2, 2, 43, 131
Offset: 2
Keywords
Examples
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.
Links
- Alessandro Polcini, Table of n, a(n) for n = 2..10000 (a(2024) corrected by Michel Marcus, Jun 14 2022)
- Index entries for sequences related to 3x+1 (or Collatz) problem
Programs
-
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; }
-
Mathematica
Array[NestWhile[If[EvenQ@ #, #/2, 3 # + 1] &, #, ! PrimeQ@ # &] &, 86, 2] (* Michael De Vlieger, Nov 07 2018 *)
-
PARI
a(n) = {while (!isprime(n), if (n % 2, n = 3*n+1, n = n/2);); n;} \\ Michel Marcus, Oct 28 2018
Formula
a(n) <= A087272(n). - Rémy Sigrist, Oct 08 2018
Comments