結果

問題 No.129 お年玉(2)
ユーザー shop_oneshop_one
提出日時 2020-04-28 00:04:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 1,197 bytes
コンパイル時間 1,171 ms
コンパイル使用メモリ 99,804 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 17:16:26
合計ジャッジ時間 4,456 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 14 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 7 ms
4,380 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 9 ms
4,384 KB
testcase_08 AC 9 ms
4,376 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 7 ms
4,376 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 9 ms
4,380 KB
testcase_19 AC 11 ms
4,380 KB
testcase_20 AC 7 ms
4,384 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 7 ms
4,376 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 12 ms
4,376 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 AC 8 ms
4,376 KB
testcase_27 AC 7 ms
4,380 KB
testcase_28 AC 7 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,384 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 3 ms
4,384 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 4 ms
4,376 KB
testcase_41 AC 5 ms
4,380 KB
testcase_42 AC 4 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 12 ms
4,380 KB
testcase_45 AC 3 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 10 ms
4,380 KB
testcase_48 AC 9 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
#define MOD 1000000000
map<ll,ll> dv(ll n){
  map<ll,ll> mp;
  for(ll i=2;i*i<=n;i++){
    ll cnt = 0;
    while(n%i==0){
      n/=i;
      cnt++;
    }
    if(cnt>0){
      mp[i]+=cnt;
    }
  }
  if(n!=1) mp[n]++;
  return mp;
}
long long pmod(long long x, long long n) {
  if(n==0) return 1;
  if(n%2==0){
    ll v = pmod(x,n/2);
    v*=v; v %= MOD;
    return v;
  }
  return (x*pmod(x,n-1))%MOD;
}
ll cmb(ll n,ll r){
  map<ll,ll> mp;
  ll res=1;
  for(ll i=1;i<=r;i++){
    map<ll,ll> t0=dv(n+1-i),t1=dv(i);
    for(auto p:t0){
      mp[p.first]+=p.second;
    }
    for(auto p:t1){
      mp[p.first]-=p.second;
    }
  }
  for(auto p:mp){
    res *= pmod(p.first,p.second);
    res %= MOD;
  }
  return res;
}
signed main(){
  init_io();
  ll n,m;
  cin >> n >> m;
  n /= 1000;
  n -= (n/m)*m;
  cout << cmb(m,n)<<endl;
}
0