private static int pow31(int p) {
      int base = 31;
      int r = 1;
      while (p != 0) {
        if ((p & 1) != 0) {
          r *= base;
        }
        base *= base;
        p >>= 1;
      }
      return r;
    }
private static int pow31(int p)