結果

問題 No.811 約数の個数の最大化
ユーザー BwambocosBwambocos
提出日時 2019-04-12 21:46:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 1,722 ms
コンパイル使用メモリ 176,652 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 17:58:29
合計ジャッジ時間 2,994 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 95 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 7 ms
5,376 KB
testcase_07 AC 11 ms
5,376 KB
testcase_08 AC 42 ms
5,376 KB
testcase_09 AC 59 ms
5,376 KB
testcase_10 AC 31 ms
5,376 KB
testcase_11 AC 94 ms
5,376 KB
testcase_12 AC 22 ms
5,376 KB
testcase_13 AC 192 ms
5,376 KB
testcase_14 AC 108 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54,
                 from main.cpp:1:
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:59:9:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:202:25: warning: 'ansN' may be used uninitialized [-Wmaybe-uninitialized]
  202 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:44:12: note: 'ansN' was declared here
   44 |         LL ansN, ansC = 0;
      |            ^~~~

ソースコード

diff #

#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

std::map<LL, LL> decomposit_prime(LL n)
{
	LL d = 2;
	std::map<LL, LL>res;
	while (d * d <= n)
	{
		if (n % d == 0)
		{
			++res[d];
			n /= d;
		}
		else ++d;
	}
	++res[n];
	return res;
}

std::vector<LL>divisor(LL num)
{
	std::vector<LL>res;
	for (LL i = 1; i * i <= num; ++i)
	{
		if (num % i == 0)
		{
			res.push_back(i);
			if ((num / i) != i) res.push_back(num / i);
		}
	}
	return res;
}

int main()
{
	LL N, K;
	in >> N >> K;

	auto N_primes = decomposit_prime(N);
	LL ansN, ansC = 0;
	for (LL i = 1; i < N; ++i)
	{
		auto M_primes = decomposit_prime(i);
		LL same = 0;
		for (auto j : M_primes) same += std::min(j.second, N_primes[j.first]);
		if (same < K) continue;
		auto M_divs = divisor(i);
		if (ansC < M_divs.size())
		{
			ansN = i;
			ansC = M_divs.size();
		}
	}

	out << ansN << std::endl;
}
0