「模板」Java ACM

Posted by StandHR on August 20, 2018
View times

输入挂

import java.util.*;
import java.math.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }

        public BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}

BigInteger 常用Methods

Modifier and Type Method and Description
BigInteger abs()
Returns a BigInteger whose value is the absolute value of this BigInteger.
BigInteger add(BigInteger val)
Returns a BigInteger whose value is (this + val).
BigInteger and(BigInteger val)
Returns a BigInteger whose value is (this & val).
BigInteger andNot(BigInteger val)
Returns a BigInteger whose value is (this & ~val).
int compareTo(BigInteger val)
Compares this BigInteger with the specified BigInteger.
BigInteger divide(BigInteger val)
Returns a BigInteger whose value is (this / val).
BigInteger[] divideAndRemainder(BigInteger val)
Returns an array of two BigIntegers containing (this / val) followed by (this % val).
double doubleValue()
Converts this BigInteger to a double.
BigInteger flipBit(int n)
Returns a BigInteger whose value is equivalent to this BigInteger with the designated bit flipped.
BigInteger gcd(BigInteger val)
Returns a BigInteger whose value is the greatest common divisor of abs(this) and abs(val).
int intValue()
Converts this BigInteger to an int.
boolean isProbablePrime(int certainty)
Returns true if this BigInteger is probably prime, false if it's definitely composite.
long longValue()
Converts this BigInteger to a long.
BigInteger max(BigInteger val)
Returns the maximum of this BigInteger and val.
BigInteger min(BigInteger val)
Returns the minimum of this BigInteger and val.
BigInteger mod(BigInteger m)
Returns a BigInteger whose value is (this % m).
BigInteger modInverse(BigInteger m)
Returns a BigInteger whose value is ($this^{-1}$ % m).
BigInteger modPow(BigInteger exponent, BigInteger m)
Returns a BigInteger whose value is ($this^{exponent}$ % m).
BigInteger multiply(BigInteger val)
Returns a BigInteger whose value is (this * val).
BigInteger negate()
Returns a BigInteger whose value is (-this).
BigInteger nextProbablePrime()
Returns the first integer greater than this BigInteger that is probably prime.
BigInteger not()
Returns a BigInteger whose value is (~this).
BigInteger or(BigInteger val)
Returns a BigInteger whose value is (this | val).
BigInteger pow(int exponent)
Returns a BigInteger whose value is ($this^{exponent}$).
BigInteger remainder(BigInteger val)
Returns a BigInteger whose value is (this % val).
BigInteger shiftLeft(int n)
Returns a BigInteger whose value is (this << n).
BigInteger shiftRight(int n)
Returns a BigInteger whose value is (this >> n).
BigInteger subtract(BigInteger val)
Returns a BigInteger whose value is (this - val).
String toString()
Returns the decimal String representation of this BigInteger.
String toString(int radix)
Returns the String representation of this BigInteger in the given radix.
static BigInteger valueOf(long val)
Returns a BigInteger whose value is equal to that of the specified long.
BigInteger xor(BigInteger val)
Returns a BigInteger whose value is (this ^ val).