結果

問題 No.2609 Decreasing GCDs
ユーザー kobaryo222kobaryo222
提出日時 2024-01-19 21:41:56
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 342 ms / 1,000 ms
コード長 4,235 bytes
コンパイル時間 2,959 ms
コンパイル使用メモリ 257,544 KB
実行使用メモリ 37,120 KB
最終ジャッジ日時 2024-01-19 21:42:08
合計ジャッジ時間 11,285 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 297 ms
37,120 KB
testcase_01 AC 310 ms
37,120 KB
testcase_02 AC 295 ms
37,120 KB
testcase_03 AC 300 ms
37,120 KB
testcase_04 AC 302 ms
37,120 KB
testcase_05 AC 311 ms
37,120 KB
testcase_06 AC 300 ms
37,120 KB
testcase_07 AC 291 ms
37,120 KB
testcase_08 AC 300 ms
37,120 KB
testcase_09 AC 314 ms
37,120 KB
testcase_10 AC 294 ms
37,120 KB
testcase_11 AC 300 ms
37,120 KB
testcase_12 AC 287 ms
37,120 KB
testcase_13 AC 305 ms
37,120 KB
testcase_14 AC 303 ms
37,120 KB
testcase_15 AC 296 ms
37,120 KB
testcase_16 AC 310 ms
37,120 KB
testcase_17 AC 300 ms
37,120 KB
testcase_18 AC 293 ms
37,120 KB
testcase_19 AC 293 ms
37,120 KB
testcase_20 AC 342 ms
37,120 KB
testcase_21 AC 298 ms
37,120 KB
testcase_22 AC 294 ms
37,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/home/mikunyan/Library/src/template.hpp"

/**
 * @brief テンプレート
 * @docs docs/template.md
 */

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using pl = pair<ll, ll>;
using vp = vector<pl>;
using vvp = vector<vp>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) std::begin(x), std::end(x)
#define make_unique(v) v.erase(unique(all(v)), v.end());
#define sum(...) accumulate(all(__VA_ARGS__), 0LL)

constexpr ll inf = 0x1fffffffffffffffLL;

template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
    is >> p.first >> p.second;
    return is;
}

template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> &p) {
    os << p.first << " " << p.second;
    return os;
}

template <class T1, class T2> void input(vector<T1> &v1, vector<T2> &v2){ rep(i, v1.size()) cin >> v1[i] >> v2[i]; }
template <class T1, class T2, class T3> void input(vector<T1> &v1, vector<T2> &v2, vector<T3> &v3) { rep(i, v1.size()) cin >> v1[i] >> v2[i] >> v3[i]; }
template <class T1, class T2, class T3, class T4> void input(vector<T1> &v1, vector<T2> &v2, vector<T3> &v3, vector<T4> &v4) { rep(i, v1.size()) cin >> v1[i] >> v2[i] >> v3[i] >> v4[i]; }

template <class T> istream &operator>>(istream &is, vector<T> &v) {
    for(auto &x : v) {
        is >> x;
    }
    return is;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for(int i = 0; i < (int)v.size(); i++) {
        if(i != (int)v.size() - 1)
            os << v[i] << " ";
        else
            os << v[i];
    }
    return os;
}

template <typename T, typename... Args>
auto vec(T x, int arg, Args... args) {
    if constexpr(sizeof...(args) == 0)
        return vector<T>(arg, x);
    else
        return vector(arg, vec<T>(x, args...));
}

template <class T> auto min(const T &a) { return *min_element(all(a)); }
template <class T> auto max(const T &a) { return *max_element(all(a)); }
template <class T> bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; }

constexpr ll bit(ll x){ return 1LL << x; }
constexpr ll msk(ll x){ return (1LL << x) - 1;}
constexpr bool stand(ll x, int i) { return x & bit(i); }

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;
#line 2 "A.cpp"

#line 1 "math/number-theory/prime-table.hpp"
/**
 * @brief Prime Table(素数テーブル)
 * @docs docs/prime-table.md
 */
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i * i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
#line 2 "math/number-theory/enumerate-primes.hpp"

vector< int > enumerate_primes(int n) {
  if(n <= 1) return {};
  auto d = prime_table(n);
  vector< int > primes;
  primes.reserve(count(begin(d), end(d), true));
  for(int i = 0; i < d.size(); i++) {
    if(d[i]) primes.push_back(i);
  }
  return primes;
}

int main(){
    ll N;
    cin >> N;
    auto primes = enumerate_primes(1e7);
    set<ll> st;
    rep(i, N, primes.size()) st.emplace(primes[i]);
    vl ans(N, 1);
    rep(i, N){
        if(i != 0) ans[i] *= primes[N - (i + 1)];
        if(i != N - 1) ans[i] *= primes[N - (i + 1) - 1];
    }
    rep(i, 1, N){
        ll x = (ans[i - 1] + ans[i] - 1) / ans[i];
        auto itr = st.lower_bound(x);
        ans[i] *= *itr;
        st.erase(itr);
    }
    cout << ans << endl;
}
0