結果

問題 No.129 お年玉(2)
ユーザー cureskolcureskol
提出日時 2020-04-06 16:51:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 840 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 175,128 KB
実行使用メモリ 4,736 KB
最終ジャッジ日時 2023-09-20 18:12:46
合計ジャッジ時間 4,059 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,452 KB
testcase_01 AC 7 ms
4,460 KB
testcase_02 AC 5 ms
4,528 KB
testcase_03 AC 5 ms
4,532 KB
testcase_04 AC 6 ms
4,444 KB
testcase_05 AC 6 ms
4,532 KB
testcase_06 AC 7 ms
4,448 KB
testcase_07 AC 8 ms
4,604 KB
testcase_08 AC 7 ms
4,468 KB
testcase_09 AC 7 ms
4,600 KB
testcase_10 AC 7 ms
4,532 KB
testcase_11 AC 6 ms
4,508 KB
testcase_12 AC 7 ms
4,456 KB
testcase_13 AC 7 ms
4,736 KB
testcase_14 AC 7 ms
4,536 KB
testcase_15 AC 7 ms
4,540 KB
testcase_16 AC 7 ms
4,524 KB
testcase_17 AC 7 ms
4,612 KB
testcase_18 AC 7 ms
4,472 KB
testcase_19 AC 7 ms
4,456 KB
testcase_20 AC 7 ms
4,460 KB
testcase_21 AC 7 ms
4,560 KB
testcase_22 AC 6 ms
4,604 KB
testcase_23 AC 7 ms
4,468 KB
testcase_24 AC 8 ms
4,536 KB
testcase_25 AC 6 ms
4,604 KB
testcase_26 AC 7 ms
4,556 KB
testcase_27 AC 7 ms
4,456 KB
testcase_28 AC 7 ms
4,472 KB
testcase_29 AC 5 ms
4,492 KB
testcase_30 AC 5 ms
4,456 KB
testcase_31 AC 5 ms
4,536 KB
testcase_32 AC 5 ms
4,452 KB
testcase_33 AC 5 ms
4,532 KB
testcase_34 AC 5 ms
4,428 KB
testcase_35 AC 5 ms
4,436 KB
testcase_36 AC 6 ms
4,500 KB
testcase_37 AC 6 ms
4,592 KB
testcase_38 AC 6 ms
4,444 KB
testcase_39 AC 6 ms
4,448 KB
testcase_40 AC 7 ms
4,544 KB
testcase_41 AC 7 ms
4,436 KB
testcase_42 AC 6 ms
4,516 KB
testcase_43 AC 6 ms
4,496 KB
testcase_44 AC 7 ms
4,704 KB
testcase_45 AC 6 ms
4,432 KB
testcase_46 AC 6 ms
4,440 KB
testcase_47 AC 7 ms
4,560 KB
testcase_48 AC 7 ms
4,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int MOD=1e9;
int pw(int n,int k){
  assert(k>=0);
  int res=1;
  while(k){
    if(k&1)(res*=n)%=MOD;
    (n*=n)%=MOD;
    k>>=1;
  }
  return res;
}
typedef pair<int,int> P;
vector<P> pri[12345];

int nCk(int n,int k){
  map<int,int> m;
  for(int i=1;i<=n;i++)for(P p:pri[i])m[p.first]+=p.second;
  for(int i=1;i<=n-k;i++)for(P p:pri[i])m[p.first]-=p.second;
  for(int i=1;i<=k;i++)for(P p:pri[i])m[p.first]-=p.second;
  int res=1;
  for(auto p:m)(res*=pw(p.first,p.second))%=MOD;
  return res;
}

signed main(){
  for(int i=2;i<12345;i++){
    if(pri[i].size())continue;
    for(int j=i;j<12345;j+=i){
      int tmp=j,c=0;
      while(tmp%i==0)tmp/=i,c++;
      pri[j].push_back(P(i,c));
    }
  }
  int n,m;cin>>n>>m;
  n/=1000;
  n%=m;
  cout<<nCk(m,n)<<endl;
}
0