组合计数
import java.util.*;
public class Main {
private static final int mod = 10007;
private static int[][] C = new int[1010][1010];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int k = sc.nextInt();
int n = sc.nextInt();
int m = sc.nextInt();
a %= mod;
b %= mod;
for (int i = 0; i <= k; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0) {
C[i][j] = 1;
}
else {
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
}
}
}
int res = C[k][n];
for (int i = 0; i < n; i++) {
res = res * a % mod;
}
for (int i = 0; i < m; i++) {
res = res * b % mod;
}
System.out.println(res);
}
}
逆元
import java.util.*;
public class Main {
private static final int mod = 10007;
private static int fastPow(int a, int k) {
a %= mod;
int res = 1;
while (k != 0) {
if ((k & 1) != 0) {
res = res * a % mod;
}
a = a * a % mod;
k >>= 1;
}
return res;
}
private static int C(int n, int m) {
int res = 1;
for(int i = 1, j = n; i <= m; i++, j--) {
res = res * j % mod * fastPow(i, mod - 2) % mod;
}
return res;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int k = sc.nextInt();
int n = sc.nextInt();
int m = sc.nextInt();
int res = C(k, n) * fastPow(a, n) % mod * fastPow(b, m) % mod;
System.out.println(res);
}
}
标签:二十八,int,211,private,nextInt,逆元,static,sc,mod
From: https://www.cnblogs.com/he0707/p/18123444/lanqiaobei28