結果

問題 No.811 約数の個数の最大化
ユーザー aa
提出日時 2019-04-13 13:03:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 788 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 169,252 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 11:35:27
合計ジャッジ時間 2,501 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 19 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,352 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 10 ms
4,348 KB
testcase_09 AC 9 ms
4,352 KB
testcase_10 AC 7 ms
4,352 KB
testcase_11 AC 13 ms
4,348 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 25 ms
4,348 KB
testcase_14 AC 18 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

vector<pair<int, int>> factors(int x)
{
	vector<pair<int, int>> ps;
	for (int i = 2; i * i <= x; i++)
	{
		if (x % i) continue;
		int cnt = 0;
		while(x % i == 0)
		{
			cnt++;
			x /= i;
		}
		ps.push_back({i, cnt});
	}
	if (x > 1) ps.push_back({x, 1});
	return ps;
}

void solve()
{
	int n, k;
	cin >> n >> k;
	int ans = 0, maxi = 0;
	for (int x = 1; x < n; x++)
	{
		int g = __gcd(x, n);
		auto gp = factors(g);
		int cnt = 0;
		for (auto p : gp)
		{
			cnt += p.second;
		}
		if (cnt < k) continue;
		auto ps = factors(x);
		int m = 1;
		for (auto p : ps)
		{
			m *= p.second + 1;
		}
		if (m > maxi)
		{
			maxi = m;
			ans = x;
		}
	}
	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}
0