結果

問題 No.811 約数の個数の最大化
ユーザー tkmst201tkmst201
提出日時 2020-11-18 19:20:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,120 bytes
コンパイル時間 3,015 ms
コンパイル使用メモリ 202,152 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-30 15:10:13
合計ジャッジ時間 3,497 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N, K;
	cin >> N >> K;
	
	vector<bool> sieve(N, true);
	vector<int> pfcnt(N, 0), divc(N, 1), cnt(N, 0);
	
	FOR(i, 2, N) {
		if (!sieve[i]) continue;
		int ncnt = 0;
		for (int m = N; m % i == 0; m /= i, ++ncnt);
		
		for (int j = 1, t = i * j; t < N; ++j, t += i) {
			if (j % i > 0) cnt[j] = 0;
			
			cnt[t] = cnt[j] + 1;
			pfcnt[t] += min(cnt[t], ncnt);
			divc[t] *= cnt[t] + 1;
			sieve[t] = false;
		}
	}
	
	int ansc = -1, ans = -1;
	FOR(i, 1, N) if (pfcnt[i] >= K && chmax(ansc, divc[i])) ans = i;
	cout << ans << endl;
	return 0;
}
0