結果
| 問題 |
No.129 お年玉(2)
|
| コンテスト | |
| ユーザー |
cureskol
|
| 提出日時 | 2020-04-06 16:51:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 5,000 ms |
| コード長 | 840 bytes |
| コンパイル時間 | 1,631 ms |
| コンパイル使用メモリ | 177,912 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-06 13:07:43 |
| 合計ジャッジ時間 | 2,861 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
#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;
}
cureskol