結果

問題 No.811 約数の個数の最大化
ユーザー izumoizumo
提出日時 2019-04-13 00:51:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,632 bytes
コンパイル時間 1,478 ms
コンパイル使用メモリ 168,928 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 09:25:02
合計ジャッジ時間 2,695 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

// 素因数分解
vector<pii> prime_factor(int n){
	vector<pii> res;
	for(int i=2; i*i<=n; ++i){
		if(n%i!=0){
			continue;
		}
		int num=0;
		while(n%i==0){
			++num;
			n/=i;
		}
		res.push_back(pii(i, num));
	}
	if(n!=1){
		res.push_back(pii(n, 1));
	}
	return res;
}

int gcd(int a, int b){
	if(b==0){
		return a;
	}
	return gcd(b, a%b);
}

int num[114514];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, k;
	cin>>n>>k;
	int cnt=0, ans=0;
	FOR(i, 1, n){
		vector<pii> v1=prime_factor(gcd(i, n));
		int tmp=0;
		for(auto x : v1){
			tmp+=x.second;
		}
		if(tmp<k){
			continue;
		}
		vector<pii> v2=prime_factor(i);
		tmp=1;
		for(auto x : v2){
			tmp*=x.second+1;
		}
		if(tmp>cnt){
			cnt=tmp;
			ans=i;
		}
	}
	cout<<ans<<'\n';
	return 0;
}
0