Пример #1
0
 public static boolean check(long n, int p) {
   BigInteger P = BigInteger.TEN.pow(p), Q = BigInteger.TEN.pow(p - 1);
   BigInteger N = BigInteger.ONE, tmp = BigInteger.valueOf(2);
   while (n > 0) {
     if ((n % 2) == 1) {
       N = N.multiply(tmp);
       N = N.mod(P);
     }
     tmp = tmp.multiply(tmp);
     tmp = tmp.mod(P);
     n >>= 1;
   }
   N = N.divide(Q);
   if (N.equals(BigInteger.ONE) || N.equals(BigInteger.valueOf(2))) return true;
   else return false;
 }
Пример #2
0
 void solve(int caseNum) {
   int n = in.nextInt();
   BigInteger[] past = new BigInteger[n], d = new BigInteger[n];
   for (int i = 0; i < n; i++) past[i] = new BigInteger(in.next());
   Arrays.sort(past);
   for (int i = 0; i < n; i++) d[i] = past[i].subtract(past[0]);
   for (int i = 2; i < n; i++) d[i] = d[i].gcd(d[i - 1]);
   BigInteger gcd = d[n - 1], mod = past[0].mod(gcd);
   System.out.printf("Case #%d: ", caseNum);
   if (mod.equals(BigInteger.ZERO)) System.out.println(0);
   else System.out.println(gcd.subtract(mod));
 }
Пример #3
0
 public static void process() {
   Arrays.sort(bookHeight);
   BigInteger sum = BigInteger.valueOf(0L);
   BigInteger temp;
   int iCount = 0;
   for (int i = bookHeight.length - 1; i >= 0; i--) {
     sum = sum.add(BigInteger.valueOf((long) (bookHeight[i])));
     temp = sum.max(b);
     iCount++;
     if (temp.equals(sum)) break;
   }
   System.out.print(iCount);
 }