結果

問題 No.129 お年玉(2)
ユーザー kenkoooo
提出日時 2015-04-20 21:01:52
言語 Java
(openjdk 23)
結果
AC  
実行時間 265 ms / 5,000 ms
コード長 661 bytes
コンパイル時間 4,226 ms
コンパイル使用メモリ 75,480 KB
実行使用メモリ 47,160 KB
最終ジャッジ日時 2024-11-27 23:42:30
合計ジャッジ時間 12,106 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong() / 1000;
		int M = sc.nextInt();
		N %= M;

		final int MOD = 1000000000;
		BigInteger ans = new BigInteger("1");
		// M_C_N を求めれば良い
		if (N == 0) {
			System.out.println(1);
			return;
		}
		for (int i = 1; i <= N; i++) {
			ans = ans.multiply(new BigInteger(String.valueOf(M - i + 1)));
			ans = ans.divide(new BigInteger(String.valueOf(i)));
		}
		ans = ans.mod(new BigInteger(String.valueOf(MOD)));
		System.out.println(ans.toString());

	}
}
	
0