java大数取模(一)

来源:互联网 发布:p2p网络借贷现状与前景 编辑:程序博客网 时间:2024/06/01 08:15
仅code,java大数取模,实际为C(n, m)。
import java.util.*;import java.math.BigInteger;public class Main{      public static void main(String[] args){          Scanner input = new Scanner(System.in);         int T;        T = input.nextInt();        int modd = 10000003;        int n, m;          while ((T--) > 0) {              n = input.nextInt();              m = input.nextInt();            BigInteger ans = BigInteger.ONE;              for (int i = m + 1; i <= n; i++) {                  ans = ans.multiply(BigInteger.valueOf(i));            }            for (int i = 1; i <= n - m; i++) {                ans = ans.divide(BigInteger.valueOf(i));            }            System.out.println(ans.mod(BigInteger.valueOf(modd)));          }      }  }  // 多组数据:while(input.hasNext())
天下尚未定,贯彻实用主义的道路。 --时值民国105年谷雨
0 0
原创粉丝点击