Advertisement
Vermiculus

Collatz's Conjecture

Nov 8th, 2011
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. final BigInteger TWO = new BigInteger("2");                        
  2. final BigInteger THREE = new BigInteger("3");                      
  3. BigInteger c = new BigInteger("12345678901234567890");                                
  4. System.out.println(c);                                            
  5. for(; c.compareTo(BigInteger.ONE) == 1; System.out.println(c)) {  
  6.     if(c.testBit(0)) { // if odd                                  
  7.         c = c.multiply(THREE).add(BigInteger.ONE); // c = 3 * c + 1
  8.     } else { // even                                              
  9.         c = c.divide(TWO); // c = 2 * c                            
  10.     }                                                              
  11. }                                                                  
  12.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement