結果

問題 No.811 約数の個数の最大化
ユーザー FF256grhyFF256grhy
提出日時 2019-04-12 21:38:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 2,871 bytes
コンパイル時間 1,866 ms
コンパイル使用メモリ 176,352 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-12 19:13:58
合計ジャッジ時間 2,728 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

bool next_array(vector<int> & a, const vector<int> & b) {
	int d = a.size();
	inc(i, d + 1) {
		if(i == d) { return false; }
		a[i]++;
		if(a[i] == b[i]) { a[i] = 0; } else { break; }
	}
	return true;
}

vector<pair<LL, LL>> prime_factorization(LL x) {
	assert(x > 0);
	
	vector<pair<LL, LL>> f;
	LL i = 2;
	while(true) {
		if(x == 1) { break; }
		
		if(i * i > x) { i = x; }
		if(x % i == 0) {
			f.EB(i, 0);
			while(x % i == 0) { f.back().SE++; x /= i; }
		}
		i++;
	}
	
	return f;
}

vector<LL> divisor(LL x) {
	assert(x > 0);
	
	auto f = prime_factorization(x);
	LL fs = f.size();
	vector<int> a(fs), b(fs);
	inc(i, fs) { b[i] = f[i].SE + 1; }
	
	vector<LL> g;
	do {
		LL v = 1;
		inc(i, fs) {
		inc(j, a[i]) {
			v *= f[i].FI;
		}
		}
		g.PB(v);
	} while(next_array(a, b));
	sort(ALL(g));
	
	return g;
}

int n, k;

int main() {
	cin >> n >> k;
	
	auto pfn = prime_factorization(n);
	pair<int, int> ma = MP(-1, -1);
	incID(i, 1, n) {
		int f = 0, I = i;
		inc(j, SI(pfn)) {
			inc(l, pfn[j].SE) {
				if(I % pfn[j].FI == 0) { I /= pfn[j].FI; f++; } else { break; }
			}
		}
		if(f >= k) { setmax(ma, MP(SI(divisor(i)), -i)); }
	}
	
	cout << -ma.SE << endl;
	
	return 0;
}
0