結果

問題 No.473 和と積の和
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-03-15 15:21:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,112 bytes
コンパイル時間 1,714 ms
コンパイル使用メモリ 171,644 KB
実行使用メモリ 414,132 KB
最終ジャッジ日時 2023-09-17 01:47:51
合計ジャッジ時間 10,650 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
413,756 KB
testcase_01 AC 106 ms
413,752 KB
testcase_02 AC 105 ms
413,756 KB
testcase_03 AC 180 ms
413,968 KB
testcase_04 AC 106 ms
414,024 KB
testcase_05 AC 107 ms
413,736 KB
testcase_06 AC 106 ms
413,800 KB
testcase_07 AC 106 ms
413,752 KB
testcase_08 AC 106 ms
414,028 KB
testcase_09 AC 106 ms
413,792 KB
testcase_10 AC 106 ms
413,860 KB
testcase_11 AC 106 ms
413,868 KB
testcase_12 AC 106 ms
413,880 KB
testcase_13 AC 107 ms
414,024 KB
testcase_14 AC 107 ms
413,868 KB
testcase_15 AC 107 ms
413,868 KB
testcase_16 AC 106 ms
413,796 KB
testcase_17 AC 104 ms
413,904 KB
testcase_18 AC 106 ms
413,864 KB
testcase_19 AC 106 ms
413,896 KB
testcase_20 AC 107 ms
413,872 KB
testcase_21 AC 106 ms
413,732 KB
testcase_22 AC 105 ms
413,800 KB
testcase_23 AC 106 ms
413,804 KB
testcase_24 AC 107 ms
413,772 KB
testcase_25 RE -
testcase_26 AC 196 ms
413,892 KB
testcase_27 AC 197 ms
413,904 KB
testcase_28 AC 107 ms
413,796 KB
testcase_29 AC 107 ms
413,740 KB
testcase_30 AC 109 ms
413,900 KB
testcase_31 AC 107 ms
413,872 KB
testcase_32 AC 106 ms
414,020 KB
testcase_33 AC 106 ms
413,760 KB
testcase_34 AC 283 ms
414,132 KB
testcase_35 AC 276 ms
414,128 KB
testcase_36 AC 107 ms
413,760 KB
testcase_37 AC 106 ms
413,804 KB
testcase_38 AC 255 ms
414,004 KB
testcase_39 AC 171 ms
413,936 KB
testcase_40 AC 181 ms
413,868 KB
testcase_41 AC 200 ms
413,976 KB
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 AC 105 ms
413,900 KB
testcase_46 AC 107 ms
413,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




int N, X;
vector<int> d;
vector<int> enumdiv(int n) {
	vector<int> S;
	for (int i = 1; i*i <= n; i++) if (n%i == 0) { S.push_back(i); if (i*i != n) S.push_back(n / i); }
	sort(S.begin(), S.end());
	return S;
}
//-----------------------------------------------------------------
int memo[1020][101][1020];
int f(int n, int m, int k) { // d[m]以上の数をk個使って、積をnとする組合せ
	if (k == 0 && n == 0) return 1;
	if (k == 0) return 0;
	if (n == 0) return 0;
	if (m == d.size()) return 0;

	if (0 <= memo[m][k][n]) return memo[m][k][n];

	int ret = f(n, m + 1, k);
	int x = d[n], kk = k;
	while (x % d[m] == 0) {
		x /= d[m];
		kk--;
		int nn = lower_bound(d.begin(), d.end(), x) - d.begin();
		ret += f(nn, m + 1, kk);
		if (kk == 0) break;
	}

	return memo[m][k][n] = ret;
}
//-----------------------------------------------------------------
int main() {
	cin >> N >> X;

	d = enumdiv(X + 1);
	rep(i, 0, 1020) rep(j, 0, 101) rep(k, 0, 1020) memo[i][j][k] = -1;
	cout << f(d.size() - 1, 1, N) << endl;
}
0