結果
| 問題 |
No.2449 square_permutation
|
| ユーザー |
|
| 提出日時 | 2023-08-31 22:59:42 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 313 ms / 2,000 ms |
| コード長 | 2,481 bytes |
| コンパイル時間 | 2,825 ms |
| コンパイル使用メモリ | 217,620 KB |
| 最終ジャッジ日時 | 2025-02-16 15:53:04 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#ifndef TEMPLATE_HPP
#define TEMPLATE_HPP
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define impl_overload4(a, b, c, d, e, ...) e
#define impl_overload5(a, b, c, d, e, f, ...) f
#define impl_overload6(a, b, c, d, e, f, g, ...) g
#define impl_overload7(a, b, c, d, e, f, g, h, ...) h
// clang-format off
#define impl_rep4(i, a, b, c) for (int i = (a); i < (b); i += (c))
#define impl_rep3(i, a, b) impl_rep4(i, a, b, 1)
#define impl_rep2(i, n) impl_rep3(i, 0, n)
#define impl_rep1(n) for (int _ = 0; _ < (n); ++_)
#define rep(...) impl_overload4(__VA_ARGS__, impl_rep4, impl_rep3, impl_rep2, impl_rep1)(__VA_ARGS__)
#define impl_rrep4(i, a, b, c) for (int i = (b) - 1; i >= (a); i -= (c))
#define impl_rrep3(i, a, b) impl_rrep4(i, a, b, 1)
#define impl_rrep2(i, n) impl_rrep3(i, 0, n)
#define rrep(...) impl_overload4(__VA_ARGS__, impl_rrep4, impl_rrep3, impl_rrep2)(__VA_ARGS__)
// clang-format on
#define all(v) std::begin(v), std::end(v)
template<typename T>
constexpr int bit(T x, unsigned int k) {
return (x >> k) & 1;
}
template<typename T>
constexpr bool chmax(T& a, const T& b) {
return a < b ? a = b, true : false;
}
template<typename T>
constexpr bool chmin(T& a, const T& b) {
return a > b ? a = b, true : false;
}
void yesno(bool b) {
std::cout << (b ? "Yes" : "No") << "\n";
}
void yes() {
yesno(true);
}
void no() {
yesno(false);
}
struct Setup {
Setup() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout << std::fixed << std::setprecision(11);
}
} setup;
#ifdef LOCAL
#include "template_local.hpp"
#else
#define show(...) ((void)0)
#endif
using uint = unsigned int;
using lint = long long;
using ulint = unsigned long long;
using namespace std;
#endif // TEMPLATE_HPP
int square_free(int v) {
for (int a = 2; a * a <= v; a++) {
if (v % (a * a) == 0) {
v /= a * a;
a--;
}
}
return v;
}
int main() {
int n;
cin >> n;
vector<int> ans(n);
vector<bool> used(n + 1);
rep (i, n) {
int p = square_free(i + 1);
int v = sqrt(n / p); // maximum v s.t. p * v^2 <= n
while (true) {
if (not used[v * v * p]) {
used[v * v * p] = true;
ans[i] = v * v * p;
break;
}
v--;
}
}
rep (i, n) cout << ans[i] << (i < n - 1 ? ' ' : '\n');
return 0;
}