Wisdom


私信TA

用户名:1085438567

访问量:1475

签 名:

等  级
排  名 59638
经  验 226
参赛次数 1
文章发表 1
年  龄 0
在职情况 学生
学  校 浙江理工大学
专  业

  自我简介:

解题思路:
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 人评分

  评论区

  • «
  • »