結果

問題 No.811 約数の個数の最大化
ユーザー ldsybldsyb
提出日時 2019-04-13 13:12:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,183 ms / 2,000 ms
コード長 877 bytes
コンパイル時間 1,604 ms
コンパイル使用メモリ 172,420 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 11:46:14
合計ジャッジ時間 7,816 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 995 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 4 ms
4,352 KB
testcase_06 AC 17 ms
4,348 KB
testcase_07 AC 31 ms
4,348 KB
testcase_08 AC 304 ms
4,348 KB
testcase_09 AC 339 ms
4,352 KB
testcase_10 AC 167 ms
4,352 KB
testcase_11 AC 975 ms
4,348 KB
testcase_12 AC 116 ms
4,348 KB
testcase_13 AC 1,178 ms
4,352 KB
testcase_14 AC 1,183 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
	auto is_prime = [](int x) {
		if (x == 2)
		{
			return true;
		}
		for (int i = 2; i * i <= x; i++)
		{
			if (x % i == 0)
			{
				return false;
			}
		}
		return true;
	};
	int n, k;
	cin >> n >> k;
	map<int, int> mp;
	for (int i = 2, j = n; j != 1; i++)
	{
		while (j % i == 0)
		{
			mp[i]++;
			j /= i;
		}
	}
	int num = 0, ans = 0;
	for (int i = 2; i < n; i++)
	{
		map<int, int> tmp;
		if (is_prime(i))
		{
			tmp[i] = 1;
		}
		else
		{
			for (int j = i, l = 2; j != 1; l++)
			{
				while (j % l == 0)
				{
					tmp[l]++;
					j /= l;
				}
			}
		}
		int puni = 0, muni = 1;
		for (auto &p : tmp)
		{
			muni *= (p.second + 1);
		}
		for (auto &p : mp)
		{
			puni += min(p.second, tmp[p.first]);
		}
		if (k <= puni && num < muni)
		{
			num = muni;
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}
0