iscsi

3n+1

Jan 20th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.io.*;
  3. import java.util.HashSet;
  4. import java.util.Set;
  5.  
  6. class FinalModifierTest {
  7.         public static void main(String[] args) {
  8.         int mx=1000001;
  9.         int[] v = new int[mx];
  10.         BigInteger m=BigInteger.valueOf(mx);
  11.         BigInteger m1=BigInteger.valueOf(1);
  12.         BigInteger m2=BigInteger.valueOf(2);
  13.         BigInteger m3=BigInteger.valueOf(3);
  14.         v[1]=1;
  15.         for(int i=2;i<mx;++i)
  16.             v[i]=0;
  17.         for(int i=2;i<mx;++i)
  18.         if(v[i]==0)
  19.         {
  20.             BigInteger a=BigInteger.valueOf(i);
  21.             int x=0;
  22.             while(a.compareTo(m)>-1 || v[a.intValue()]==0)
  23.             {
  24.                 if(a.testBit(0))
  25.                 {
  26.                     a=a.multiply(m3);
  27.                     a=a.add(m1);
  28.                 }
  29.                 else
  30.                 {
  31.                     a=a.divide(m2);
  32.                 }
  33.                 x=x+1;
  34.             }
  35.             v[i]=v[a.intValue()]+x;
  36.             a=BigInteger.valueOf(i);
  37.             while(a.compareTo(m)>-1 || v[a.intValue()]==0)
  38.             {
  39.                 if(a.testBit(0))
  40.                 {
  41.                     a=a.multiply(m3);
  42.                     a=a.add(m1);
  43.                 }
  44.                 else
  45.                 {
  46.                     a=a.divide(m2);
  47.                 }
  48.                 if(a.intValue()<mx)
  49.                 {
  50.                     v[a.intValue()]=x;
  51.                 }
  52.                 x=x-1;
  53.             }
  54.         }
  55.         int res=0,res2=0;
  56.         for(int i=2;i<mx;++i)
  57.         if(v[i]>res)
  58.         {
  59.             res=v[i];
  60.             res2=i;
  61.         }
  62.         System.out.println(res2);
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment