結果

問題 No.811 約数の個数の最大化
ユーザー lumc_lumc_
提出日時 2019-04-12 21:37:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 1,594 bytes
コンパイル時間 1,109 ms
コンパイル使用メモリ 115,592 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 19:11:47
合計ジャッジ時間 2,515 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

// O(N^.5)
/// --- primeFactors {{{ ///
#include <map>
map< ll, int > primeFactors(ll n) {
  map< ll, int > res;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) n /= i, res[i]++;
  }
  if(n != 1) res[n] = 1;
  return res;
}
/// }}}--- ///

int popcount(int x) {
  x = (x & 0x55555555) + ((x & 0xAAAAAAAA) >> 1);
  x = (x & 0x33333333) + ((x & 0xCCCCCCCC) >> 2);
  x = (x & 0x0F0F0F0F) + ((x & 0xF0F0F0F0) >> 4);
  x = (x & 0x00FF00FF) + ((x & 0xFF00FF00) >> 8);
  x = (x & 0x0000FFFF) + ((x & 0xFFFF0000) >> 16);
  return x;
}


int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, k;
  cin >> n >> k;
  auto pf = primeFactors(n);
  multiset<int> v;
  for(auto p : pf) {
    while(p.second--) v.insert(p.first);
  }

  pair<int, int> best(-10, 0);

  for(int i = 1; i < n; i++) {
    auto pf = primeFactors(i);
    multiset<int> w;
    int num = 1;
    for(auto p : pf) {
      num *= p.second + 1;
      while(p.second--) w.insert(p.first);
    }
    vector<int> z;
    set_intersection(begin(v), end(v), begin(w), end(w), inserter(z, end(z)));
    if(z.size() >= k) {
      best = max(best, make_pair(num, -i));
    }
  }
  cout << -best.second << endl;

  return 0;
}
0