标签:
1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 public class Main { 5 public static BigInteger lucas(BigInteger n, BigInteger m, BigInteger p) { 6 if (m.equals(BigInteger.ZERO)) 7 return BigInteger.ONE; 8 return BigInteger 9 .valueOf(f(n.mod(p).longValue(), m.mod(p).longValue())) 10 .multiply(lucas(n.divide(p), m.divide(p), p)).mod(p); 11 } 12 13 public static long f(long n, long m) { 14 if (m > n) 15 return 1; 16 if (n == m || m == 0) 17 return 1; 18 if (m > n - m) 19 m = n - m; 20 long tmpi = 1, tmpn = 1, s1 = 1, s2 = 1, ans = 1; 21 for (int i = 1; i <= m; i++) { 22 tmpi = i; 23 tmpn = n - i + 1; 24 s1 = s1 * tmpi % 999101; 25 s2 = s2 * tmpn % 999101; 26 } 27 ans = s2 * pow1(s1, 999099) % 999101; 28 return ans % 999101; 29 } 30 31 public static long pow1(long x, long n) { 32 if (x == 1) 33 return 1; 34 if (n == 0) 35 return 1; 36 else { 37 while ((n & 1) == 0) { 38 n >>= 1; 39 x = (x * x) % 999101; 40 } 41 } 42 long result = x % 999101; 43 n >>= 1; 44 while (n != 0) { 45 x = (x * x) % 999101; 46 ; 47 if ((n & 1) != 0) 48 result = result * x % 999101; 49 n >>= 1; 50 } 51 return result; 52 } 53 54 public static void main(String[] args) { 55 Scanner sc = new Scanner(System.in); 56 BigInteger n = new BigInteger(sc.nextLine()); 57 BigInteger m = new BigInteger(sc.nextLine()); 58 int k = Integer.parseInt(sc.nextLine()); 59 BigInteger md = new BigInteger("999101"); 60 long Cnm = lucas(n, m, md).longValue() % 999101; 61 long sum = 0; 62 if (Cnm != 0) { 63 int[][] a = new int[k][k]; 64 int h = 1; 65 for (int i = 0; i < k; i++) { 66 for (int j = 0; j < k; j++) { 67 if (j >= h) 68 a[i][j] = 0; 69 else { 70 if (j == 0 || j == h - 1) 71 a[i][j] = 1; 72 else { 73 a[i][j] = (a[i - 1][j - 1] * (h - j) + a[i - 1][j]) % 999101; 74 } 75 } 76 } 77 h++; 78 } 79 long m1 = 1, n1 = 1; 80 long x = n.subtract(new BigInteger(k + "")) 81 .mod(md.subtract(BigInteger.ONE)).longValue(); 82 long n3 = pow1(2, x); 83 for (int i = k - 1; i >= 0; i--) { 84 n1 = n3 * pow1(2, i) % 999101; 85 m1 = m1 86 * (n.subtract(new BigInteger((k - 1 - i) + "")).mod(md) 87 .longValue()) % 999101; 88 sum = (sum + m1 * a[k - 1][i] * n1) % 999101; 89 } 90 sum = sum * Cnm % 999101; 91 } 92 System.out.println(sum); 93 } 94 95 }
评测点序号 | 评测结果 | 得分 | CPU使用 | 内存使用 | 下载评测数据 |
---|---|---|---|---|---|
1 | 正确 | 10.00 | 187ms | 23.37MB | 输入 输出 |
2 | 正确 | 10.00 | 171ms | 23.19MB | 输入 输出 |
3 | 正确 | 10.00 | 156ms | 23.46MB | 输入 输出 |
4 | 正确 | 10.00 | 202ms | 23.36MB | 输入 输出 |
5 | 正确 | 10.00 | 202ms | 23.15MB | 输入 输出 |
6 | 正确 | 10.00 | 187ms | 23.86MB | 输入 输出 |
7 | 正确 | 10.00 | 202ms | 23.94MB | 输入 输出 |
8 | 正确 | 10.00 | 327ms | 25.40MB | 输入 输出 |
9 | 正确 | 10.00 | 483ms | 30.19MB | 输入 输出 |
10 | 正确 | 10.00 | 436ms | 31.25MB | 输入 输出 |
标签:
原文地址:http://www.cnblogs.com/wuqianling/p/5369844.html