結果

問題 No.811 約数の個数の最大化
ユーザー chocoruskchocorusk
提出日時 2019-04-12 21:33:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,603 bytes
コンパイル時間 1,509 ms
コンパイル使用メモリ 113,088 KB
実行使用メモリ 21,128 KB
最終ジャッジ日時 2023-10-12 18:57:53
合計ジャッジ時間 2,636 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,180 KB
testcase_01 AC 5 ms
8,268 KB
testcase_02 AC 81 ms
19,448 KB
testcase_03 AC 4 ms
8,180 KB
testcase_04 AC 5 ms
8,176 KB
testcase_05 AC 5 ms
8,444 KB
testcase_06 AC 8 ms
9,112 KB
testcase_07 AC 10 ms
9,856 KB
testcase_08 AC 33 ms
13,912 KB
testcase_09 AC 38 ms
14,528 KB
testcase_10 AC 20 ms
12,384 KB
testcase_11 AC 75 ms
19,420 KB
testcase_12 AC 19 ms
11,480 KB
testcase_13 AC 95 ms
21,128 KB
testcase_14 AC 88 ms
20,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int MAX=100001;
vector<ll> prime;
bool isprime[MAX];
void sieve(){
	for(ll i=3; i<MAX; i+=2){
		isprime[i]=1;
	}
	isprime[2]=1;
	prime.push_back(2);
	for(ll i=3; i<MAX; i++){
		if(isprime[i]){
			prime.push_back(i);
			for(ll j=2*i; j<MAX; j+=i){
				isprime[j]=0;
			}
		}
	}
	return;
}
int main()
{
    int n, k; cin>>n>>k;
    map<int, int> mp[100001];
    sieve();
    for(int i=0; i<prime.size(); i++){
        int p=prime[i];
        if(p>n) break;
        for(int i=p; i<=n; i+=p){
            int x=i, e=0;
            while(x%p==0){
                x/=p; e++;
            }
            mp[i][p]=e;
        }
    }
    vector<P> ans;
    for(int i=2; i<n; i++){
        int ct=0;
        for(auto pe:mp[n]){
            int p=pe.first, e=pe.second;
            auto itr=mp[i].find(p);
            if(itr==mp[i].end()) continue;
            else{
                ct+=min(itr->second, e);
            }
        }
        if(ct<k) continue;
        int d=1;
        for(auto pe:mp[i]){
            d*=(pe.second+1);
        }
        ans.push_back(P(-d, i));
    }
    sort(ans.begin(), ans.end());
    cout<<ans[0].second<<endl;
    return 0;
}
0