結果

問題 No.811 約数の個数の最大化
ユーザー tomatoma
提出日時 2019-04-12 21:49:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,868 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 174,832 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 19:43:29
合計ジャッジ時間 2,982 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

//f
//in: number
//out: prime numbers
map<int, int> prime_factorization(int n)
{
	map<int, int> res;
	int check = 2;

	while (check*check <= n) {
		if (n%check == 0) {
			n /= check;
			if (res.find(check) == res.end())res[check] = 0;
			res[check]++;
		}
		else {
			check++;
		}
	}
	if (n != 1) {
		if (res.find(n) == res.end())res[n] = 0;
		res[n]++;
	}
	//sort(res.begin(), res.end());
	return res;
}

int count_same_prime(map<int, int> primes, map<int, int> target) {
	int res = 0;
	for (auto itr = primes.begin(); itr != primes.end(); ++itr) {
		int num = itr->first;
		int cnt = itr->second;
		if (target.find(num) == target.end())continue;
		int cnt2 = target[num];
		res += min(cnt, cnt2);
	}
	return res;
}

int count_division(map<int, int> primes) {
	int res = 1;
	for (auto itr = primes.begin(); itr != primes.end(); ++itr) {
		int tmp = (itr->second) + 1;
		res *= tmp;
	}
	return res;
}

int N, K;


int main()
{
	cin >> N >> K;
	int res = -1;
	int score = -1;

	auto target = prime_factorization(N);
	FOR(i, 1, N) {
		if (i == 24) {
			cerr<<endl;
		}
		map<int, int> primes = prime_factorization(i);
		int cnt = count_same_prime(target, primes);
		if (cnt < K)continue;
		int nscore = count_division(primes);
		if (nscore > score) {
			res = i;
			score = nscore;
		}
		
	}

	cout << res << endl;
	//cin>>N;
	return 0;
}
0