結果

問題 No.129 お年玉(2)
ユーザー CleyLCleyL
提出日時 2020-03-15 19:52:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,073 bytes
コンパイル時間 682 ms
コンパイル使用メモリ 73,088 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-04 02:52:14
合計ジャッジ時間 1,902 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
struct SieveEratos{
  vector<bool> t;
  SieveEratos(int n):t(n+1,true){
    t[0] = t[1] = false;
    for(int i = 2; n >= i; i++){
      if(t[i]){
        for(int j = i+i; n >= j; j+=i){
          t[j] = false;
        }
      }
    }
  }
  bool operator[](int x){return t[x];}
};
const int mod = 1000000000;
long long C(int n,int r,vector<int> P){
	//nCr = nC(n-r)
	if(r > n/2)r = n-r;

	int a[n];for(int i = 0; r > i; i++)a[i] = n-i;

	for(int p:P){
		//素数p > rだったらforに入らないので
		if(p > r)break;
		for(int q = p; r >= q; q *= p){
			int m = n%q;
			for(int i = m, j = 0; r/q > j;i+=q,j++){
				//cout << i << " " << p << endl;
				a[i]/=p;
			}
		}
	}
	
	long mul = 1;
	for(int i = 0; r > i; i++){
		//cout << a[i] << " ";
		mul = (mul*a[i])%mod;
	}
	//cout << endl;
	return mul;

}
int main(){
	vector<int> P;
	SieveEratos A(1000);
	for(int i = 0; 1000 > i; i++){
		if(A[i])P.push_back(i);
	}
	long long n,m;cin>>n>>m;

	n = n/1000;
	int N = m;
	int R = n%m;

	cout << C(N,R,P) << endl;
}
0