1. BigInteger 的使用
1.1. 判素数
package 模板;import java.math.BigInteger;
import java.util.Scanner;public class 判素数 {static Scanner in = new Scanner(System.in);public static void main(String[] args) {int q = in.nextInt();while (q-- > 0) {BigInteger a = new BigInteger(in.next());if (a.isProbablePrime(20)) {System.out.println(a);} else {System.out.println(a.nextProbablePrime());}}}
}
1.2. 快速幂
package 模板;import java.math.BigInteger;
import java.util.Scanner;public class 快速幂 {static Scanner in = new Scanner(System.in);public static void main(String[] args) {BigInteger b = new BigInteger(in.next());BigInteger p = new BigInteger(in.next());BigInteger k = new BigInteger(in.next());System.out.println(b.modPow(p, k));}
}
1.3. 求逆元
package 模板;import java.math.BigInteger;
import java.util.Scanner;public class 逆元 {static Scanner in = new Scanner(System.in);public static void main(String[] args) {int q = in.nextInt();while (q-- > 0) {BigInteger a = new BigInteger(in.next());BigInteger b = new BigInteger(in.next());System.out.println(a.modInverse(b));}}
}
2. Arrays
- 直接对于 int 对象排序使用的是快排
- 对于 Integer 对象排序使用的是归并排序