結果

問題 No.2081 Make a Test Case of GCD Subset
ユーザー miscalcmiscalc
提出日時 2022-09-25 22:33:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 5,092 bytes
コンパイル時間 4,387 ms
コンパイル使用メモリ 281,716 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-06-01 23:40:59
合計ジャッジ時間 8,110 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,812 KB
testcase_01 AC 25 ms
5,248 KB
testcase_02 AC 27 ms
5,376 KB
testcase_03 AC 25 ms
5,376 KB
testcase_04 AC 22 ms
5,376 KB
testcase_05 AC 28 ms
5,376 KB
testcase_06 AC 26 ms
5,376 KB
testcase_07 AC 21 ms
5,376 KB
testcase_08 AC 29 ms
5,376 KB
testcase_09 AC 22 ms
5,376 KB
testcase_10 AC 26 ms
5,376 KB
testcase_11 AC 26 ms
5,376 KB
testcase_12 AC 26 ms
5,376 KB
testcase_13 AC 31 ms
5,376 KB
testcase_14 AC 38 ms
5,376 KB
testcase_15 AC 23 ms
5,376 KB
testcase_16 AC 30 ms
5,376 KB
testcase_17 AC 27 ms
5,376 KB
testcase_18 AC 17 ms
6,940 KB
testcase_19 AC 31 ms
5,376 KB
testcase_20 AC 20 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 22 ms
5,376 KB
testcase_23 AC 45 ms
5,376 KB
testcase_24 AC 7 ms
5,376 KB
testcase_25 AC 6 ms
5,376 KB
testcase_26 AC 7 ms
5,376 KB
testcase_27 AC 43 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll safemod(ll A, ll M) {ll res = A % M; if (res < 0) res += M; return res;}
ll divfloor(ll A, ll B) {if (B < 0) {return divfloor(-A, -B);} return (A - safemod(A, B)) / B;}
ll divceil(ll A, ll B) {if (B < 0) {return divceil(-A, -B);} return divfloor(A + B - 1, B);}
ll pow_ll(ll A, ll B) {if (A == 0 || A == 1) {return A;} if (A == -1) {return B & 1 ? -1 : 1;} ll res = 1; for (int i = 0; i < B; i++) {res *= A;} return res;}
ll logfloor(ll A, ll B) {assert(A >= 2); ll res = 0; for (ll tmp = 1; tmp <= B / A; tmp *= A) {res++;} return res;}
ll logceil(ll A, ll B) {assert(A >= 2); ll res = 0; for (ll tmp = 1; tmp < B; tmp *= A) {res++;} return res;}
ll arisum_ll(ll a, ll d, ll n) { return n * a + (n & 1 ? ((n - 1) >> 1) * n : (n >> 1) * (n - 1)) * d; }
ll arisum2_ll(ll a, ll l, ll n) { return n & 1 ? ((a + l) >> 1) * n : (n >> 1) * (a + l); }
ll arisum3_ll(ll a, ll l, ll d) { assert((l - a) % d == 0); return arisum2_ll(a, l, (l - a) / d + 1); }
template<class T> void unique(vector<T> &V) {V.erase(unique(V.begin(), V.end()), V.end());}
template<class T> void sortunique(vector<T> &V) {sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end());}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)
template<class T> void printvec(const vector<T> &V) {int _n = V.size(); for (int i = 0; i < _n; i++) cout << V[i] << (i == _n - 1 ? "" : " ");cout << '\n';}
template<class T> void printvect(const vector<T> &V) {for (auto v : V) cout << v << '\n';}
template<class T> void printvec2(const vector<vector<T>> &V) {for (auto &v : V) printvec(v);}
//*
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
//using mint = modint1000000007;
//using mint = modint;
//*/

class eratosthenes
{
public:
  int N;
  vector<bool> isprime;
  vector<int> primecount;
  vector<int> primes;
  vector<int> minfactor;
  vector<int> mobius;

  eratosthenes(int n)
  {
    N = n;
    isprime.assign(n + 1, true);
    primecount.assign(n + 1, 0);
    minfactor.assign(n + 1, -1);
    mobius.assign(n + 1, 1);
    isprime[0] = false, isprime[1] = false;
    minfactor[1] = 1;

    for (int p = 2; p <= n; p++)
    {
      primecount[p] = primecount[p - 1];
      if (!isprime[p])
        continue;
      primecount[p]++;

      primes.emplace_back(p);
      minfactor[p] = p;
      mobius[p] = -1;

      for (int k = 2, q = 2 * p; q <= n; k++, q += p)
      {
        isprime[q] = false;
        if (minfactor[q] == -1)
          minfactor[q] = p;
        if (k % p == 0)
          mobius[q] = 0;
        else
          mobius[q] = -mobius[q];
      }
    }
  }

  vector<pll> factorize(ll n)
  {
    vector<pll> ret;
    while (n > 1)
    {
      int p = minfactor[n];
      int e = 0;
      while (minfactor[n] == p)
      {
        n /= p;
        e++;
      }
      ret.emplace_back(make_pair(p, e));
    }
    return ret;
  }

  ll L;
  vector<vector<ll>> primefactors2;
  void rangesieve(ll l, ll r)
  {
    L = l;
    ll R = r;
    primefactors2.resize(R - L + 1);
    for (ll p = 2; p * p <= R; p++)
    {
      if (!isprime[p])
        continue;
      for (ll v = divceil(L, p) * p; v <= R; v += p)
      {
        primefactors2[v - L].emplace_back(p);
      }
    }
  }
  vector<pll> factorize2(ll v)
  {
    vector<pll> ret;
    ll vv = v;
    const auto &pfs = primefactors2[v - L];
    for (auto p : pfs)
    {
      ll e = 0;
      while (vv % p == 0)
      {
        vv /= p;
        e++;
      }
      ret.emplace_back(make_pair(p, e));
    }
    if (vv > 1)
      ret.emplace_back(make_pair(vv, 1));
    return ret;
  }
};

int main()
{
  ll M;
  cin >> M;

  if (M == 0)
  {
    cout << "1\n1\n";
    return 0;
  }

  eratosthenes er(100000);

  vector<ll> B;
  for (ll i = 40; i >= 0; i--)
  {
    if (M & (1LL << i))
    {
      B.push_back(i);
      B.push_back(1);
    }
  }
  sort(B.begin(), B.end(), greater<ll>());

  set<ll> st;
  for (auto p : er.primes)
    st.emplace(p);

  vector<ll> A;
  for (auto b : B)
  {
    ll p = b != 1 ? *st.begin() : *st.rbegin();
    for (ll i = 0; i < b; i++)
    {
      A.push_back(p);
    }
    st.erase(p);
  }

  ll N = A.size();
  {
    for (ll i = 0; i < N - 1; i++)
    {
      if (A.at(i) == A.at(i + 1))
      {
        auto it = upper_bound(st.begin(), st.end(), 100000 / A.at(i));
        it--;
        A.at(i) *= *it;
        st.erase(it);
      }
    }
  }
  
  cout << N << endl;
  printvec(A);

  /*
  set<ll> st;
  for (auto a : A)
    st.emplace(a);
  assert(st.size() == N);
  //*/

  /*
  ll ans = 0;
  for (ll b = 0; b < (1LL << N); b++)
  {
    ll g = 0;
    for (ll i = 0; i < N; i++)
    {
      if (b & (1LL << i))
        g = gcd(g, A.at(i));
    }
    if (g >= 2)
      ans++;
  }
  cout << ans << endl;
  //*/
}
0