예제 #1
0
 public static final BigInteger powTen(int exponent) {
   if ((exponent >= 0) && (exponent < bigIntTenPow.length)) {
     return bigIntTenPow[exponent];
   } else {
     return bigIntTen.pow(exponent);
   }
 }
예제 #2
0
  static {
    // TODO: DecimalFormat uses ROUND_HALF_EVEN, not ROUND_HALF_UP
    // Float: precision of 7 (6 digits after .)
    floatFormatter = new DecimalFormat();
    floatFormatter.applyPattern("0.######E0");

    // Double: precision of 16 (15 digits after .)
    doubleFormatter = new DecimalFormat();
    doubleFormatter.applyPattern("0.###############E0");

    bigIntTenPow = new BigInteger[20];
    bigIntMinUnscaled = new BigInteger[20];
    bigIntMaxUnscaled = new BigInteger[20];

    for (int i = 0; i < bigIntTenPow.length; i++) {
      bigIntTenPow[i] = bigIntTen.pow(i);
      if (i < 19) {
        bigIntMaxUnscaled[i] = bigIntTenPow[i].subtract(BigInteger.ONE);
        bigIntMinUnscaled[i] = bigIntMaxUnscaled[i].negate();
      } else {
        bigIntMaxUnscaled[i] = BigInteger.valueOf(Long.MAX_VALUE);
        bigIntMinUnscaled[i] = BigInteger.valueOf(Long.MIN_VALUE);
      }
    }
  }
예제 #3
0
  /** @param args */
  public static void main(String[] args) { // array: 99*99 = 9801;
    BigInteger[] array = new BigInteger[9801];
    int cont = 0;

    for (int i = 2; i < 101; i++) {
      BigInteger dos = new BigInteger("2");
      BigInteger uno = new BigInteger("1");

      for (int j = 2; j < 101; j++) {
        array[cont] = dos.pow(i);
        cont++;
        dos = dos.add(uno);
      }
    }

    for (int x = 0; x < array.length; x++) {
      for (int j = 1; j + x < array.length; j++) {
        int res = array[x].compareTo(array[x + j]);
        if (res == 0) {
          cont--;
          System.out.println("salto!");

          break;
        }
      }
    }
    System.out.println(cont);
  }
예제 #4
0
파일: uva619.java 프로젝트: de-yu/uva
 public static void abcd(String str) {
   BigInteger sum = BigInteger.ZERO;
   StringBuffer n = new StringBuffer("");
   for (int i = 0; i < str.length(); i++) {
     BigInteger ab = BigInteger.valueOf(((int) str.charAt(i)) - 96);
     sum = sum.add(div.pow(str.length() - i - 1).multiply(ab));
   }
   String s = sum.toString();
   for (int i = 0; i < s.length(); i++) {
     if (i % 3 == 0 && i != 0) n.insert(0, ",");
     n.insert(0, s.charAt(s.length() - i - 1));
   }
   while (str.length() < 22) str = str + " ";
   System.out.println(str + "" + n);
 }
예제 #5
0
  public static void main(String args[]) {
    int t;
    Scanner s = new Scanner(System.in);
    t = s.nextInt();

    BigInteger b1 = new BigInteger("0");
    int b2;
    BigInteger b3 = new BigInteger("0");
    BigInteger b4 = new BigInteger("10");
    while (t > 0) {
      b1 = s.nextBigInteger();
      b2 = s.nextInt();
      b3 = b1.pow(b2);
      System.out.println(b3.mod(b4));
      t--;
    }
    s.close();
  }