結果

問題 No.811 約数の個数の最大化
ユーザー Mcpu3Mcpu3
提出日時 2019-09-22 21:15:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 859 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 73,764 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 07:23:51
合計ジャッジ時間 1,684 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 45 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 5 ms
4,348 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 21 ms
4,348 KB
testcase_09 AC 24 ms
4,348 KB
testcase_10 AC 15 ms
4,348 KB
testcase_11 AC 39 ms
4,348 KB
testcase_12 AC 11 ms
4,348 KB
testcase_13 AC 76 ms
4,348 KB
testcase_14 AC 49 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iterator>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N, K, i = 2;
	cin >> N >> K;
	int a = N;
	pair<int, int> b;
	vector<int> c;
	while (a >= i * i) {
		if (0 == a % i) {
			a /= i;
			c.push_back(i);
		}
		else ++i;
	}
	c.push_back(a);
	for (i = 1; i < N; ++i) {
		a = i;
		int d = 0, j = 2;
		vector<int> e, f;
		while (a >= j * j) {
			if (0 == a % j) {
				a /= j;
				e.push_back(j);
			}
			else ++j;
		}
		e.push_back(a);
		set_intersection(c.begin(), c.end(), e.begin(), e.end(), inserter(f, f.end()));
		if (K <= f.size()) {
			for (j = 1; j * j <= i; ++j) {
				if (0 == i % j) {
					++d;
					if (i / j != j) ++d;
				}
			}
			if (b.first < d) {
				b.first = d;
				b.second = i;
			}
		}
	}
	cout << b.second;
}
0