結果

問題 No.811 約数の個数の最大化
ユーザー okok
提出日時 2019-04-12 22:41:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,965 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 80,012 KB
実行使用メモリ 6,716 KB
最終ジャッジ日時 2023-10-12 22:18:22
合計ジャッジ時間 1,536 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 110000
#define MAX_PN  1100000

int PN[MAX_PN+2];
int used[MAX], fuga[MAX];

void huga(int t, int x){
	if(PN[t]) return;
	for(int i = t*t; i <= x; i+=t)
		PN[i] = true;
}

void Sieve_of_Eratosthenes(int x){
	PN[0]=PN[1]=PN[4]=true;
	for(int i = 6; (i-1)*(i-1) <= x; i+=6)
		huga(i-1,x),huga(i+1,x);
	for(int i = 6; i <= x; i+=6)
		PN[i]=PN[i+2]=PN[i+3]=PN[i+4]=true;
}


signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, K, t;
	int ans = 1, temp = 1 , max_ = 0;
	
	cin>>N>>K;
	
	Sieve_of_Eratosthenes(N);
	
	vector<int> d, s;
	
	t = N;
	
	for(int i = 2; i*i <= t; i++){
		
		if(t%i == 0)s.push_back(i);
		
		while(t%i == 0){
			d.push_back(i);	
			used[i]++;
			t /= i;
		}
	}
	
	if(t != 1){
		used[t]++;
		d.push_back(t);
		s.push_back(t);
	}
	
	sort(d.begin(), d.end());
	sort(s.begin(), s.end());
	
	// cout<<s[0]<<" "<<s[1]<<endl;
	
	for(int i = 0; i < s.size(); i++){
		int num = s[i];
		for(int k = num; k <= N; k+= num){
			int cc = 0, n = k;
			
			while(n%num == 0){
				n /= num;
				cc++;
			}
			
			// cout<<k<<" "<<cc<<" "<<used[num]<<endl;
			fuga[k] += min(cc,used[num]);
		}
	}
	
	for(int i = 1; i < N; i++){
		if(fuga[i] >= K){
			int num = i, con = 0, con2 = 1;
			for(int j = 2; j*j <= num; j++){
				con = 0;
				while(num%j == 0){
					con++;
					num /= j;
				}
				con2 *= con+1;
			}
			
			if(num != 1) con2 *= 2;
			
			// cout<<i<<" "<<con2<<endl;
			if(con2 > max_){
				max_ = con2;
				ans = i;
			}
		}
	}
	// for(int i = 1; i <= N; i++){
		// cout<<i<<" "<<fuga[i]<<endl;
	// }
	
	cout<<ans<<endl;
	
	return 0;
}
0