結果

問題 No.811 約数の個数の最大化
ユーザー tekihei2317tekihei2317
提出日時 2019-04-12 22:00:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 851 bytes
コンパイル時間 1,594 ms
コンパイル使用メモリ 173,696 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 20:18:17
合計ジャッジ時間 3,042 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 100 ms
4,356 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 3 ms
4,352 KB
testcase_06 AC 7 ms
4,352 KB
testcase_07 AC 10 ms
4,348 KB
testcase_08 AC 43 ms
4,352 KB
testcase_09 AC 48 ms
4,348 KB
testcase_10 AC 29 ms
4,348 KB
testcase_11 AC 94 ms
4,348 KB
testcase_12 AC 25 ms
4,352 KB
testcase_13 AC 105 ms
4,352 KB
testcase_14 AC 104 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,K; cin>>N>>K;

    int _N=N;
    map<int,int> cnt;
    for(int i=2;i*i<=_N;i++){
	while(_N%i==0){
	    cnt[i]++;
	    _N/=i;
	}
    }
    if(_N!=1) cnt[_N]=1;

    int ans1=-1,ans2=0; //約数の個数の最大値と、それを与える数
    for(int i=2;i<N;i++){
	int tmp=i;
	map<int,int> c;
	for(int j=2;j*j<=tmp;j++){
	    while(tmp%j==0){
		c[j]++;
		tmp/=j;
	    }
	}
	if(tmp!=1) c[tmp]=1;

	int x=0,y=1;
	for(pint p:cnt){
	    x+=min(p.second,c[p.first]);
	}
	for(pint p:c){
	    y*=(p.second+1);
	}
	if(x>=K and y>ans1){
	    ans1=y;
	    ans2=i;
	}
    }
    cout<<ans2<<endl;
}


0