結果

問題 No.2609 Decreasing GCDs
ユーザー haihamabossuhaihamabossu
提出日時 2024-01-19 23:14:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 1,309 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 207,032 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-19 23:15:00
合計ジャッジ時間 3,356 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

const ll MAX = 50000;
vector<ll> prime_list() {
  vector<ll> res;
  vector<bool> table(MAX + 10, true);
  for (ll i = 2; i <= MAX; i++) {
    if (table[i]) {
      res.push_back(i);
      for (ll j = i * 2; j <= MAX; j += i) {
        table[j] = false;
      }
    }
  }
  return res;
}

void solve() {
  ll n;
  cin >> n;
  auto list = prime_list();
  vector<ll> ans(n, 0);
  rep(i, n) { ans[n - i - 1] = list[i] * list[i + 1]; }
  for (ll i = 1; i < n; i++) {
    for (const auto &j : list) {
      if (ans[i - 1] >= ans[i] * j) {
        continue;
      }
      bool ok = true;
      if (i < n) {
        auto g1 = __gcd(ans[i - 1], ans[i]);
        auto g2 = __gcd(ans[i - 1], ans[i] * j);
        ok &= g1 == g2;
      }
      if (i < n - 1) {
        auto g1 = __gcd(ans[i + 1], ans[i]);
        auto g2 = __gcd(ans[i + 1], ans[i] * j);
        ok &= g1 == g2;
      }
      if (ok) {
        ans[i] *= j;
        break;
      }
    }
  }
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << ans[i];
  }
  cout << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int T = 1;
  for (int t = 0; t < T; t++) {
    solve();
  }
  return 0;
}
0