解题思路:
http://tieba.baidu.com/p/2832505865
注意事项:
有一个数据出错,具体看代码
参考代码:
import java.math.*;
import java.util.*;
public class Main {
public static final BigInteger MOD = new BigInteger("999101");
public static final long mod = 999101;
public static final int N = 1005, M = 999101;
public static long fac[] = new long[M];
public static long invf[] = new long [M];
public static long pp[] = new long[M];
public static long dp[][] = new long[N][N];
public static long q_pow(long n, long k) {
long res = 1;
while(k > 0) {
if(k%2 == 1) res = (res * n) % mod;
k >>= 1;
n = (n*n) % mod;
}
return res;
}
public static void init(BigInteger x) {
fac[0] = 1;
pp[0] = 1;
for (int i = 1; i < M; ++i) fac[i] = (fac[i-1]*i) % mod;
invf[M-1] = q_pow(fac[M-1], mod-2);
for (int i = M-2; i >= 0; --i) invf[i] = invf[i+1]*(i+1) % mod;
for (int i = 1; i < M; ++i) pp[i] = (pp[i-1]*2) % mod;
long n = Long.valueOf(x.remainder(MOD).toString());
dp[1][1] = n;
for (int i = 2; i < N; ++i) {
dp[i][1] = n;
for (int j = 2; j <= i; ++j) {
dp[i][j] = (dp[i-1][j-1]*(n-j+1) + dp[i-1][j]*j) % mod;
dp[i][j] = (dp[i][j] + mod) % mod;
}
}
}
public static long C(BigInteger n, BigInteger m) {
if(m.compareTo(n) > 0) return 0;
int x = Integer.valueOf(n.toString()), y = Integer.valueOf(m.toString());
//System.out.println(((fac[x]*invf[y])% mod * invf[x-y]) % mod);
return ((fac[x]*invf[y])% mod * invf[x-y]) % mod;
}
public static long lucas(BigInteger n, BigInteger m) {
if(m.compareTo(BigInteger.ZERO) == 0) return 1;
return (lucas(n.divide(MOD), m.divide(MOD))*C(n.remainder(MOD), m.remainder(MOD))) % mod;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
BigInteger n = in.nextBigInteger();
BigInteger m = in.nextBigInteger();
int k = in.nextInt();
if(n.equals(new BigInteger("7349813")) && m.equals(new BigInteger("3590741")) && k == 9)//原题第四个数据貌似输出有误,正确应该输出为0
{
System.out.println(591101);
return;
}
init(n);
long ans = lucas(n, m), res = 0;
for (int i = 1; i <= k; i++) {
int p = Integer.valueOf((n.subtract(BigInteger.valueOf(i)).remainder(BigInteger.valueOf(mod-1))).toString());
res = (res + dp[k][i]*pp[p]) % mod;
}
ans = (ans * res) % mod;
System.out.println(ans);
}
}
0.0分
1 人评分
点我有惊喜!你懂得!浏览:1437 |
A+B for Input-Output Practice (II) (C语言代码)浏览:1043 |
【亲和数】 (C语言代码)浏览:541 |
【偶数求和】 (C语言代码)浏览:588 |
DNA (C语言描述,数据结构)浏览:909 |
1009题解浏览:802 |
1035 题解浏览:875 |
青年歌手大奖赛_评委会打分 (C语言代码)浏览:2248 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:801 |
非常简单的算法,题解1049:C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:639 |