結果

問題 No.811 約数の個数の最大化
コンテスト
ユーザー Bwambocos
提出日時 2019-04-12 21:46:45
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 944 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,108 ms
コンパイル使用メモリ 189,928 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-04 14:08:18
合計ジャッジ時間 1,858 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/istream:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/sstream:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/complex:50,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ccomplex:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:133,
                 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/15.2.0_1/include/c++/15/bits/ostream.h:212:25: warning: 'ansN' may be used uninitialized [-Wmaybe-uninitialized]
  212 |       { 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 #
raw source code

#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