login
Start with n, iterate the process x -> x*3-1 until reaching a prime; then a(n) is the number of iterations required, or 0 if no prime is ever reached.
1

%I #10 Aug 05 2012 10:32:34

%S 1,1,2,1,2,1,2,1,6,1,8,3,2,1,2,1,2,1,2,1,4892,47,4,1,10,5,2,1,2,1,44,

%T 7,2,1,2,1,4,1,2,9,12,11,2,1,2,1,2,3,4,1,4,367,4,5,2,1,2,1,12,1,12,

%U 4891,2,1,46,1,2,3,2,3,4,3,2,9,6,1,4,1,4,1,4,27

%N Start with n, iterate the process x -> x*3-1 until reaching a prime; then a(n) is the number of iterations required, or 0 if no prime is ever reached.

%C At least one iteration must be made.

%C Corresponding primes: 2, 5, 23, 11, 41, 17, 59, 23, 6197, 29, 68891, 311, 113, 41, 131, 47, 149, 53, 167, 59, ...

%e n=3: 3 => 8 => 23, so a(3)=2.

%e n=9: 9 => 26 => 77 => 230 => 689 => 2066 => 6197, so a(9)=6.

%o (Java)

%o import java.math.BigInteger;

%o public class A215136 {

%o public static void main (String[] args) {

%o long n, t, step;

%o BigInteger BI1 = BigInteger.valueOf(1);

%o BigInteger BI3 = BigInteger.valueOf(3);

%o for (n=1; n<3333; ++n) {

%o BigInteger bn = BigInteger.valueOf(n);

%o t = n;

%o for (step=1; step<9999; ++step) {

%o bn = bn.multiply(BI3).subtract(BI1);

%o t = (t*3+614889782588491409L) % 614889782588491410L; // A002110(15)

%o if (t<=47 || (t%2>0 && t%3>0 && t%5>0 && t%7>0 && t%11>0 && t%13>0 && t%17>0 && t%19>0 && t%23>0 && t%29>0 && t%31>0 && t%37>0 && t%41>0 && t%43>0 && t%47>0) ) {

%o if (bn.isProbablePrime(2)) {

%o if (bn.isProbablePrime(80)) break;

%o }

%o }

%o }

%o if (step==9999) System.out.printf("---(%d), ", n);

%o else System.out.printf("%d, ", step);

%o }

%o }

%o }

%Y Cf. A000040, A078681.

%K nonn

%O 1,3

%A _Alex Ratushnyak_, Aug 04 2012