結果
問題 | No.129 お年玉(2) |
ユーザー |
![]() |
提出日時 | 2015-01-17 00:02:18 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 233 ms / 5,000 ms |
コード長 | 1,639 bytes |
コンパイル時間 | 3,479 ms |
コンパイル使用メモリ | 88,872 KB |
実行使用メモリ | 46,024 KB |
最終ジャッジ日時 | 2024-11-27 23:00:29 |
合計ジャッジ時間 | 11,958 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
import java.io.BufferedInputStream; import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; import java.util.Map.Entry; public class Main { public static final int C = 1000000007; static final int CY = 1000000000; //static boolean MAP[][]; static long N; static long M; static int MAX = -1; //static int tic[][]; static int MAP[][]; //static int max; static int DP[][][]; static int ST[][]; //static int p[]; //static ArrayList<HashSet<Integer>> al; static TreeMap<Integer, ArrayList<Integer>> hm; //static ArrayList<Integer> al; //static int a[][]; //static char[][] ch; //static ArrayList<HashMap<Long, Long>> al; //static String a[]; //static String str; public static void main(String[] args) { StringBuilder sb = new StringBuilder(); BufferedInputStream bs = new BufferedInputStream(System.in); Scanner sc = new Scanner(bs); N = sc.nextLong()/1000; M =sc.nextInt(); BigInteger bi = new BigInteger("0"); long ans = 0; long let = N%M; //for (int i=1; i <= let; i++) { bi = bi.add(calcCombination(M, let)); //} if (bi.equals(new BigInteger("0"))) { bi = new BigInteger("1"); } System.out.println(bi.mod(new BigInteger(CY+""))); } /** * aCbを計算して返す */ static BigInteger calcCombination(long a, long b) { BigInteger rtn = new BigInteger("1"); long k = Math.min(b, a-b); if (k < 0) { return new BigInteger("0"); } for (long i=1; i <= k;i++) { rtn = rtn.multiply(new BigInteger((a-(i-1))+"")); rtn = rtn.divide(new BigInteger(i + "")); } return rtn; } }