結果

問題 No.129 お年玉(2)
ユーザー alpha_virginisalpha_virginis
提出日時 2015-06-19 21:32:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3,430 ms / 5,000 ms
コード長 693 bytes
コンパイル時間 1,871 ms
コンパイル使用メモリ 144,564 KB
実行使用メモリ 4,452 KB
最終ジャッジ日時 2023-08-18 17:21:19
合計ジャッジ時間 35,802 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
4,380 KB
testcase_01 AC 3,430 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1,057 ms
4,376 KB
testcase_06 AC 498 ms
4,452 KB
testcase_07 AC 1,266 ms
4,380 KB
testcase_08 AC 1,595 ms
4,376 KB
testcase_09 AC 366 ms
4,376 KB
testcase_10 AC 1,593 ms
4,376 KB
testcase_11 AC 663 ms
4,376 KB
testcase_12 AC 11 ms
4,380 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 503 ms
4,376 KB
testcase_15 AC 427 ms
4,376 KB
testcase_16 AC 726 ms
4,380 KB
testcase_17 AC 255 ms
4,380 KB
testcase_18 AC 1,391 ms
4,376 KB
testcase_19 AC 2,158 ms
4,380 KB
testcase_20 AC 918 ms
4,380 KB
testcase_21 AC 314 ms
4,376 KB
testcase_22 AC 846 ms
4,380 KB
testcase_23 AC 1,470 ms
4,376 KB
testcase_24 AC 2,568 ms
4,380 KB
testcase_25 AC 587 ms
4,376 KB
testcase_26 AC 1,148 ms
4,376 KB
testcase_27 AC 1,021 ms
4,376 KB
testcase_28 AC 801 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 5 ms
4,380 KB
testcase_37 AC 3 ms
4,384 KB
testcase_38 AC 82 ms
4,376 KB
testcase_39 AC 60 ms
4,428 KB
testcase_40 AC 169 ms
4,376 KB
testcase_41 AC 421 ms
4,376 KB
testcase_42 AC 195 ms
4,376 KB
testcase_43 AC 12 ms
4,380 KB
testcase_44 AC 2,681 ms
4,380 KB
testcase_45 AC 108 ms
4,380 KB
testcase_46 AC 12 ms
4,380 KB
testcase_47 AC 2,058 ms
4,380 KB
testcase_48 AC 1,714 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

long gcd(long a, long b) {
  if( a < b ) std::swap(a, b);
  while( b != 0 ) {
    a = a % b;
    std::swap(a, b);
  }
  return a;
}

long nCr(long a, long b) {
  long w[100000] = {};
  long ret = 1;
  long temp;
  long g;

  for(int i = 0; i < b; ++i) {
    w[i] = a - i;
  }
  for(int i = 1; i <= b; ++i) {
    temp = i;
    for(int j = 0; j < b; ++j) {
      g = gcd(w[j], temp);
      w[j] /= g;
      temp /= g;
    }
  }

  for(int i = 0; i < b; ++i) {
    ret *= w[i];
    ret %= 1000000000;
  }
  return ret;
}

int main() {
  
  long N, M;

  std::cin >> N;
  std::cin >> M;

  std::cout << nCr(M, (N-(N/M/1000*1000)*M)/1000) << std::endl;
  
  return 0;
}
	
0