結果

問題 No.473 和と積の和
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-03-15 15:20:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,108 bytes
コンパイル時間 1,590 ms
コンパイル使用メモリ 170,996 KB
実行使用メモリ 7,580 KB
最終ジャッジ日時 2023-09-17 01:46:36
合計ジャッジ時間 5,118 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,456 KB
testcase_01 AC 5 ms
7,360 KB
testcase_02 AC 4 ms
7,360 KB
testcase_03 RE -
testcase_04 AC 5 ms
7,424 KB
testcase_05 AC 4 ms
7,356 KB
testcase_06 AC 4 ms
7,312 KB
testcase_07 AC 4 ms
7,348 KB
testcase_08 AC 4 ms
7,352 KB
testcase_09 AC 5 ms
7,288 KB
testcase_10 AC 4 ms
7,352 KB
testcase_11 AC 4 ms
7,420 KB
testcase_12 AC 4 ms
7,420 KB
testcase_13 AC 5 ms
7,296 KB
testcase_14 AC 4 ms
7,316 KB
testcase_15 AC 4 ms
7,548 KB
testcase_16 AC 5 ms
7,320 KB
testcase_17 AC 4 ms
7,364 KB
testcase_18 AC 5 ms
7,388 KB
testcase_19 AC 4 ms
7,500 KB
testcase_20 AC 4 ms
7,360 KB
testcase_21 AC 4 ms
7,296 KB
testcase_22 AC 4 ms
7,576 KB
testcase_23 WA -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 5 ms
7,304 KB
testcase_29 AC 4 ms
7,580 KB
testcase_30 AC 5 ms
7,308 KB
testcase_31 AC 5 ms
7,360 KB
testcase_32 AC 5 ms
7,364 KB
testcase_33 AC 5 ms
7,372 KB
testcase_34 RE -
testcase_35 RE -
testcase_36 AC 6 ms
7,500 KB
testcase_37 AC 5 ms
7,312 KB
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 AC 5 ms
7,368 KB
testcase_46 AC 4 ms
7,384 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[101][101][101];
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, 101) rep(j, 0, 101) rep(k, 0, 101) memo[i][j][k] = -1;
	cout << f(d.size() - 1, 1, N) << endl;
}
0