fork download
  1. import java.math.BigInteger;
  2. class Ideone{
  3. static final int c11=25,c23=30;
  4. static final int b11=(1<<c11)-1,b23=(1<<c23)-1;
  5. static BigInteger i2b(int[]a){
  6. return BigInteger.valueOf((long)a[2])
  7. .add(BigInteger.valueOf((long)a[1]).shiftLeft(c23))
  8. .add(BigInteger.valueOf((long)a[0]).shiftLeft(c23+c23));
  9. }
  10. static int[] add(int[]a,int[]b){
  11. int[]c={0,0,0}; int z=0;
  12. z+=a[2]+b[2]; c[2]=z&b23; z>>=c23;
  13. z+=a[1]+b[1]; c[1]=z&b23; z>>=c23;
  14. z+=a[0]+b[0]; c[0]=z&b11;
  15. return c;
  16. }
  17. static int[] mul(int[]a,int[]b){
  18. int[]c={0,0,0}; long z=0L;
  19. z+=(long)a[2]*(long)b[2];
  20. c[2]=(int)(z&(long)b23); z>>=(long)c23;
  21. z+=(long)a[1]*(long)b[2]+(long)a[2]*(long)b[1];
  22. c[1]=(int)(z&(long)b23); z>>=(long)c23;
  23. z+=(long)a[0]*(long)b[2]+(long)a[1]*(long)b[1]+(long)a[2]*(long)b[0];
  24. c[0]=(int)(z&(long)b11);
  25. return c;
  26. }
  27. public static void main(String[] args){
  28. int[] b={0,0, 2};
  29. int[] a={0,0,27};
  30. int[] s={0,0,27};
  31. int[] t;
  32. long ms0 = System.currentTimeMillis();
  33. for (long i = 1L; i < 1099511627776L/30000L ; i++){
  34. t = mul(a,a); a = mul(t,a); s = add(s,a);
  35. }
  36. long ms = System.currentTimeMillis()-ms0;
  37. System.out.println(i2b(s)+"/"+ms);
  38. System.out.println("1099511627776L => "+30000d*ms/(1000*60*60*24));
  39. }
  40. }
Success #stdin #stdout 0.56s 2184192KB
stdin
Standard input is empty
stdout
17396612018432151008312873/511
1099511627776L => 0.17743055555555556