結果

問題 No.811 約数の個数の最大化
ユーザー ngtkanangtkana
提出日時 2020-03-13 12:26:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 204,004 KB
実行使用メモリ 4,720 KB
最終ジャッジ日時 2023-08-14 03:39:39
合計ジャッジ時間 2,915 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define endl enjoy_codeforces
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    lint n,k;std::cin>>n>>k;
    std::vector<lint>sieve(n,0);
    for(lint p=1;p<n;p++){
        for(lint i=p;i<n;i+=p){
            sieve.at(i)++;
        }
    }
    std::vector<lint>common(n,0);
    auto div=[&,n]()mutable{
        std::vector<std::pair<lint,lint>>div;
        for(lint p=2;p*p<=n;p++){
            if(n%p!=0)continue;
            lint i=0;for(;n%p==0;i++)n/=p;
            div.emplace_back(p,i);
        }
        if(n!=1)div.emplace_back(n,1);
        return div;
    }();
    for(auto[p,m]:div){
        for(lint q=p;m--;q*=p){
            for(lint i=q;i<n;i+=q){
                common.at(i)++;
            }
        }
    }
    lint ans=0,max=0;
    for(lint i=n-1;i>=1;i--){
        if(k<=common.at(i)&&max<=sieve.at(i)){
            ans=i;
            max=sieve.at(i);
        }
    }
    std::cout<<ans<<'\n';
}
0