結果
問題 | No.129 お年玉(2) |
ユーザー |
|
提出日時 | 2016-05-04 11:22:50 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 340 ms / 5,000 ms |
コード長 | 923 bytes |
コンパイル時間 | 2,817 ms |
コンパイル使用メモリ | 77,380 KB |
実行使用メモリ | 46,256 KB |
最終ジャッジ日時 | 2024-11-28 00:27:21 |
合計ジャッジ時間 | 15,871 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
package yukicoder; import java.math.BigInteger; import java.util.Scanner; public class Main{ public static void main(String[] args)throws Exception{ new Main().solve(); } final int mod=1_000_000_000; void solve(){ Scanner sc=new Scanner(System.in); long n=sc.nextLong(); int m=sc.nextInt(); n=n%(m*1000); n=n/1000; BigInteger ans=nCk(m,(int)n); //n個の●をm人に配分する。 System.out.println(ans); } long[] fact; long[] inv_fact; //1~nの数字からk個取る方法の数 BigInteger nCk(int n,int k){ if(n<k)return BigInteger.ZERO; else{ return fact_big(n).divide( fact_big(n-k).multiply(fact_big(k))).remainder(BigInteger.valueOf(mod)); } } long fact(int n){ long ans=1; for(int i=1;i<=n;i++)ans*=i; return ans; } BigInteger fact_big(int n){ BigInteger ans=BigInteger.ONE; for(int i=1;i<=n;i++)ans=ans.multiply(BigInteger.valueOf(i)); return ans; } }