結果

問題 No.811 約数の個数の最大化
ユーザー okok
提出日時 2019-04-12 22:41:00
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,965 bytes
コンパイル時間 807 ms
コンパイル使用メモリ 79,928 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 20:31:35
合計ジャッジ時間 1,367 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0