/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Caleb Bryson, Alexander Haag */ import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.math.BigInteger; import java.util.Scanner; public class Collatz { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(new File("collatz.in")); PrintWriter out = new PrintWriter(new File("collatz.out")); while(in.hasNext()){ out.println(collatz(in.nextBigInteger())); } out.close(); } public static int collatz(BigInteger input) { BigInteger[] array = new BigInteger[3000]; int i = 0; array[i] = input; while (!array[i].equals(BigInteger.ONE)) { if (array[i].mod(BigInteger.valueOf(2)).equals(BigInteger.ZERO)) { BigInteger k = array[i].divide(BigInteger.valueOf(2)); array[i+1] = k; i++; }else{ BigInteger j = array[i].multiply(BigInteger.valueOf(3)).add(BigInteger.ONE); array[i+1] = j; i++; } } return i; } }