結果
| 問題 | No.3441 Sort Permutation 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-02 00:46:17 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 20,423 bytes |
| 記録 | |
| コンパイル時間 | 4,496 ms |
| コンパイル使用メモリ | 362,436 KB |
| 実行使用メモリ | 153,100 KB |
| 最終ジャッジ日時 | 2026-03-02 00:47:24 |
| 合計ジャッジ時間 | 58,385 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 16 TLE * 11 |
コンパイルメッセージ
In file included from ../library/my_template.hpp:5:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ciso646:49:6: warning: #warning "<ciso646> is not a standard header since C++20, use <version> to detect implementation-specific macros" [-Wcpp]
49 | # warning "<ciso646> is not a standard header since C++20, use <version> to detect implementation-specific macros"
| ^~~~~~~
In file included from ../library/my_template.hpp:18:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ccomplex:51:4: warning: #warning "<ccomplex> is deprecated in C++17, use <complex> instead" [-Wcpp]
51 | # warning "<ccomplex> is deprecated in C++17, use <complex> instead"
| ^~~~~~~
In file included from ../library/my_template.hpp:21:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/cstdalign:50:6: warning: #warning "<cstdalign> is deprecated in C++17, remove the #include" [-Wcpp]
50 | # warning "<cstdalign> is deprecated in C++17, remove the #include"
| ^~~~~~~
In file included from ../library/my_template.hpp:22:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/cstdbool:50:6: warning: #warning "<cstdbool> is deprecated in C++17, remove the #include" [-Wcpp]
50 | # warning "<cstdbool> is deprecated in C++17, remove the #include"
| ^~~~~~~
In file included from ../library/my_template.hpp:24:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ctgmath:50:6: warning: #warning "<ctgmath> is deprecated in C++17, use <complex> or <cmath> instead" [-Wcpp]
50 | # warning "<ctgmath> is deprecated in C++17, use <complex> or <cmath> instead"
| ^~~~~~~
ソースコード
// the library can be found here: https://maspypy.github.io/library/
// note, the version used here could be different from the official version
// BEGIN: b.cpp
#line 1 "b.cpp"
// BEGIN: ../library/my_template.hpp
#line 1 "../library/my_template.hpp"
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#if defined(MASPY_LOCAL)
#include <my_template_compiled.hpp>
#else
using namespace std;
using ll = long long;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i128 = __int128;
using u128 = unsigned __int128;
// f128 is not supported so we will use
using f128 = long double;
template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'010'000'000;
template <>
constexpr ll infty<ll> = 2'020'000'000'000'000'000;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * 2'000'000'000'000'000'000;
template <>
constexpr double infty<double> = numeric_limits<double>::infinity();
template <>
constexpr long double infty<long double> =
numeric_limits<long double>::infinity();
using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using pq_max = priority_queue<T>;
template <class T>
using pq_min = priority_queue<T, vector<T>, greater<T>>;
#define vv(type, name, h, ...) \
vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) \
vector<vector<vector<type>>> name( \
h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...) \
vector<vector<vector<vector<type>>>> name( \
a, vector<vector<vector<type>>>( \
b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a) - 1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a) - 1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b) - 1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define len(x) ll(x.size())
#define elif else if
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define stoi stoll
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_sgn(int x) { return (__builtin_parity(unsigned(x)) & 1 ? -1 : 1); }
int popcnt_sgn(u32 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(ll x) { return (__builtin_parityll(x) & 1 ? -1 : 1); }
int popcnt_sgn(u64 x) { return (__builtin_parityll(x) & 1 ? -1 : 1); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
template <typename T>
T kth_bit(int k) {
return T(1) << k;
}
template <typename T>
bool has_kth_bit(T x, int k) {
return x >> k & 1;
}
int __lg(unsigned long long x) {
return x ? (63 - __builtin_clzll(x)) : -1;
}
template <typename UINT>
struct all_bit {
struct iter {
UINT s;
iter(UINT s) : s(s) {}
int operator*() const { return lowbit(s); }
iter &operator++() {
s &= s - 1;
return *this;
}
bool operator!=(const iter) const { return s != 0; }
};
UINT s;
all_bit(UINT s) : s(s) {}
iter begin() const { return iter(s); }
iter end() const { return iter(0); }
};
template <typename UINT>
struct all_subset {
static_assert(is_unsigned<UINT>::value);
struct iter {
UINT s, t;
bool ed;
iter(UINT s) : s(s), t(s), ed(0) {}
UINT operator*() const { return s ^ t; }
iter &operator++() {
(t == 0 ? ed = 1 : t = (t - 1) & s);
return *this;
}
bool operator!=(const iter) const { return !ed; }
};
UINT s;
all_subset(UINT s) : s(s) {}
iter begin() const { return iter(s); }
iter end() const { return iter(0); }
};
template <typename T>
T floor(T a, T b) {
return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
T q = floor(x, y);
return {q, x - q * y};
}
constexpr ll TEN[] = {
1LL,
10LL,
100LL,
1000LL,
10000LL,
100000LL,
1000000LL,
10000000LL,
100000000LL,
1000000000LL,
10000000000LL,
100000000000LL,
1000000000000LL,
10000000000000LL,
100000000000000LL,
1000000000000000LL,
10000000000000000LL,
100000000000000000LL,
1000000000000000000LL,
};
template <typename T, typename U>
T SUM(const U &A) {
return std::accumulate(A.begin(), A.end(), T{});
}
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
template <class C, class T>
inline long long LB(const C &c, const T &x) {
return lower_bound(c.begin(), c.end(), x) - c.begin();
}
template <class C, class T>
inline long long UB(const C &c, const T &x) {
return upper_bound(c.begin(), c.end(), x) - c.begin();
}
#define UNIQUE(x) \
sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()
template <typename T>
T POP(deque<T> &que) {
T a = que.front();
que.pop_front();
return a;
}
template <class T, class Container, class Compare>
T POP(priority_queue<T, Container, Compare> &que) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(vc<T> &que) {
T a = que.back();
que.pop_back();
return a;
}
template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
if (check_ok) assert(check(ok));
while (llabs(ok - ng) > 1) {
auto x = (ng + ok) / 2;
(check(x) ? ok : ng) = x;
}
return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
FOR(iter) {
double x = (ok + ng) / 2;
(check(x) ? ok : ng) = x;
}
return (ok + ng) / 2;
}
template <class T, class S>
inline bool chmax(T &a, const S &b) {
T c = max<T>(a, b);
bool changed = (c != a);
a = c;
return changed;
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
T c = min<T>(a, b);
bool changed = (c != a);
a = c;
return changed;
}
// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
vc<int> A(S.size());
FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
return A;
}
template <typename T, typename U>
vc<T> cumsum(const vc<U> &A, int off = 1) {
int N = A.size();
vc<T> B(N + 1);
FOR(i, N) { B[i + 1] = B[i] + A[i]; }
if (off == 0) B.erase(B.begin());
return B;
}
// stable sort
template <typename T>
vc<int> argsort(const vc<T> &A) {
vc<int> ids(len(A));
iota(all(ids), 0);
sort(all(ids),
[&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
return ids;
}
// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
vc<T> B(len(I));
FOR(i, len(I)) B[i] = A[I[i]];
return B;
}
template <typename T, typename... Vectors>
void concat(vc<T> &first, const Vectors &...others) {
vc<T> &res = first;
(res.insert(res.end(), others.begin(), others.end()), ...);
}
#endif
// END: ../library/my_template.hpp
#line 2 "b.cpp"
// BEGIN: ../library/nt/extgcd.hpp
#line 1 "../library/nt/extgcd.hpp"
// {g,x,y}, ax+by=g
template <typename T>
tuple<T, T, T> extgcd(T a, T b) {
static_assert(is_same_v<T, int> || is_same_v<T, ll>);
T x = 1, y = 0, x1 = 0, y1 = 1;
while (b != 0) {
T q = a / b;
swap(a %= b, b);
T X = x - q * x1, Y = y - q * y1;
x = x1, y = y1, x1 = X, y1 = Y;
}
return {a, x, y};
}
tuple<ll, ll, ll, ll> Farey_lr(ll a, ll b) {
assert(a > 0 && b > 0);
/*
Farey 数列で、a/b が最初に現れるときの、左右を求める。
a/b = 19/12 → (x1/y1, x2/y2) = (11/7, 8/5) → (11,7,8,5) を返す。
*/
if (a == b) return {0, 1, 1, 0};
ll q = (a - 1) / b;
auto [x1, y1, x2, y2] = Farey_lr(b, a - q * b);
return {q * x2 + y2, x2, q * x1 + y1, x1};
}
tuple<ll, ll, ll> extgcd2(ll a, ll b) {
// ax + by = d の最小解 (x, y, d) を返す。
// (|x|+|y|, x) に関する辞書順最小とする。
auto [x1, y1, x2, y2] = Farey_lr(a, b);
tie(x1, y1) = mp(y1, -x1);
tie(x2, y2) = mp(-y2, x2);
ll g = a * x1 + b * y1;
pi key1 = mp(abs(x1) + abs(y1), x1);
pi key2 = mp(abs(x2) + abs(y2), x2);
return (key1 < key2 ? mt(x1, y1, g) : mt(x2, y2, g));
}
// END: ../library/nt/extgcd.hpp
#line 3 "b.cpp"
// BEGIN: ../library/nt/divisors.hpp
#line 1 "../library/nt/divisors.hpp"
// BEGIN: ../library/nt/factor.hpp
#line 1 "../library/nt/factor.hpp"
// BEGIN: ../library/random/base.hpp
#line 1 "../library/random/base.hpp"
u64 RNG_64() {
static u64 x_ = u64(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count()) * 10150724397891781847ULL;
x_ ^= x_ << 7;
return x_ ^= x_ >> 9;
}
u64 RNG(u64 lim) { return RNG_64() % lim; }
ll RNG(ll l, ll r) { return l + RNG_64() % (r - l); }
// END: ../library/random/base.hpp
#line 4 "../library/nt/factor.hpp"
// BEGIN: ../library/nt/primetest.hpp
#line 1 "../library/nt/primetest.hpp"
// BEGIN: ../library/mod/mongomery_modint.hpp
#line 1 "../library/mod/mongomery_modint.hpp"
// odd mod.
// x の代わりに rx を持つ
template <int id, typename U1, typename U2>
struct Mongomery_modint {
using mint = Mongomery_modint;
inline static U1 m, r, n2;
static constexpr int W = numeric_limits<U1>::digits;
static void set_mod(U1 mod) {
assert(mod & 1 && mod <= U1(1) << (W - 2));
m = mod, n2 = -U2(m) % m, r = m;
FOR(5) r *= 2 - m * r;
r = -r;
assert(r * m == U1(-1));
}
static U1 reduce(U2 b) { return (b + U2(U1(b) * r) * m) >> W; }
U1 x;
Mongomery_modint() : x(0) {}
Mongomery_modint(U1 x) : x(reduce(U2(x) * n2)){};
U1 val() const {
U1 y = reduce(x);
return y >= m ? y - m : y;
}
mint &operator+=(mint y) {
x = ((x += y.x) >= m ? x - m : x);
return *this;
}
mint &operator-=(mint y) {
x -= (x >= y.x ? y.x : y.x - m);
return *this;
}
mint &operator*=(mint y) {
x = reduce(U2(x) * y.x);
return *this;
}
mint operator+(mint y) const { return mint(*this) += y; }
mint operator-(mint y) const { return mint(*this) -= y; }
mint operator*(mint y) const { return mint(*this) *= y; }
bool operator==(mint y) const {
return (x >= m ? x - m : x) == (y.x >= m ? y.x - m : y.x);
}
bool operator!=(mint y) const { return not operator==(y); }
mint pow(ll n) const {
assert(n >= 0);
mint y = 1, z = *this;
for (; n; n >>= 1, z *= z)
if (n & 1) y *= z;
return y;
}
};
template <int id>
using Mongomery_modint_32 = Mongomery_modint<id, u32, u64>;
template <int id>
using Mongomery_modint_64 = Mongomery_modint<id, u64, u128>;
// END: ../library/mod/mongomery_modint.hpp
#line 3 "../library/nt/primetest.hpp"
bool primetest(const u64 x) {
assert(x < u64(1) << 62);
if (x == 2 or x == 3 or x == 5 or x == 7) return true;
if (x % 2 == 0 or x % 3 == 0 or x % 5 == 0 or x % 7 == 0) return false;
if (x < 121) return x > 1;
const u64 d = (x - 1) >> lowbit(x - 1);
using mint = Mongomery_modint_64<202311020>;
mint::set_mod(x);
const mint one(u64(1)), minus_one(x - 1);
auto ok = [&](u64 a) -> bool {
auto y = mint(a).pow(d);
u64 t = d;
while (y != one && y != minus_one && t != x - 1) y *= y, t <<= 1;
if (y != minus_one && t % 2 == 0) return false;
return true;
};
if (x < (u64(1) << 32)) {
for (u64 a: {2, 7, 61})
if (!ok(a)) return false;
} else {
for (u64 a: {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) {
if (!ok(a)) return false;
}
}
return true;
}// END: ../library/nt/primetest.hpp
#line 5 "../library/nt/factor.hpp"
template <typename mint>
ll rho(ll n, ll c) {
assert(n > 1);
const mint cc(c);
auto f = [&](mint x) { return x * x + cc; };
mint x = 1, y = 2, z = 1, q = 1;
ll g = 1;
const ll m = 1LL << (__lg(n) / 5);
for (ll r = 1; g == 1; r <<= 1) {
x = y;
FOR(r) y = f(y);
for (ll k = 0; k < r && g == 1; k += m) {
z = y;
FOR(min(m, r - k)) y = f(y), q *= x - y;
g = gcd(q.val(), n);
}
}
if (g == n) do {
z = f(z);
g = gcd((x - z).val(), n);
} while (g == 1);
return g;
}
ll find_prime_factor(ll n) {
assert(n > 1);
if (primetest(n)) return n;
FOR(100) {
ll m = 0;
if (n < (1 << 30)) {
using mint = Mongomery_modint_32<20231025>;
mint::set_mod(n);
m = rho<mint>(n, RNG(0, n));
} else {
using mint = Mongomery_modint_64<20231025>;
mint::set_mod(n);
m = rho<mint>(n, RNG(0, n));
}
if (primetest(m)) return m;
n = m;
}
assert(0);
return -1;
}
// ソートしてくれる
vc<pair<ll, int>> factor(ll n) {
assert(n >= 1);
vc<pair<ll, int>> pf;
FOR(p, 2, 100) {
if (p * p > n) break;
if (n % p == 0) {
ll e = 0;
do { n /= p, e += 1; } while (n % p == 0);
pf.eb(p, e);
}
}
while (n > 1) {
ll p = find_prime_factor(n);
ll e = 0;
do { n /= p, e += 1; } while (n % p == 0);
pf.eb(p, e);
}
sort(all(pf));
return pf;
}
vc<pair<ll, int>> factor_by_lpf(ll n, vc<int>& lpf) {
vc<pair<ll, int>> res;
while (n > 1) {
int p = lpf[n];
int e = 0;
while (n % p == 0) {
n /= p;
++e;
}
res.eb(p, e);
}
return res;
}
// END: ../library/nt/factor.hpp
#line 2 "../library/nt/divisors.hpp"
// sort はしない
vc<ll> divisors_by_pf(const vc<pair<ll, int>>& pf) {
vi div = {1};
for (auto&& [p, e]: pf) {
ll n = len(div);
ll pp = 1;
FOR3(i, 1, e + 1) {
pp *= p;
FOR(j, n) div.eb(div[j] * pp);
}
}
return div;
}
// sort はしない
vc<ll> divisors(ll N) {
auto pf = factor(N);
return divisors_by_pf(pf);
}
// sort はしない
vc<ll> divisors_by_lpf(ll N, vc<int>& lpf) {
auto pf = factor_by_lpf(N, lpf);
return divisors_by_pf(pf);
}// END: ../library/nt/divisors.hpp
#line 4 "b.cpp"
#include <iostream>
std::vector<std::vector<ll>> g_divisor_table;
void solve() {
int n; std::cin >> n;
std::vector<int> v(n);
for (auto &it : v) {
std::cin >> it;
it--;
}
std::vector<int> used(n, 0);
std::vector<std::vector<int>> cycles;
for (int i = 0; i < n; i++) {
if (used[i]) continue;
int curr = i;
used[curr] = 1;
cycles.push_back({});
auto &cycle = cycles.back();
cycle.push_back(i);
while (!used[v[curr]]) {
curr = v[curr];
used[curr] = 1;
cycle.push_back(curr);
}
}
// for (auto cycle: cycles) {
// for (auto it: cycle) {
// std::cout << it << " ";
// }
// std::cout << std::endl;
// }
// maps divisor to number of cycles which won't get the discount
std::map<ll, int> no_discount;
std::map<ll, int> edge_count;
ll live_cycles = 0;
// for each cycle index we will add it everywhere it participates in
std::map<ll, std::set<int>> participants;
// std::cout << "cycles.size() = " << cycles.size() << std::endl;
for (int i = 0; i < cycles.size(); i++) {
// std::cout << "iter: " << i << " cycle size: " << cycles[i].size() << std::endl;
if (cycles[i].size() <= 1) continue;
live_cycles += 1;
ll com = std::abs(cycles[i][0] - cycles[i].back());
// std::cout << "com = " << com << std::endl;
edge_count[com] += 1;
if (cycles[i].size() >= 3) {
for (auto d : g_divisor_table[com]) {
participants[d].insert(i);
}
}
for (int j = 1; j < cycles[i].size(); j++) {
ll expr = std::abs(cycles[i][j] - cycles[i][j - 1]);
if (cycles[i].size() >= 3) {
edge_count[expr] += 1;
for (auto d : g_divisor_table[expr]) {
participants[d].insert(i);
}
}
com = std::get<0>(extgcd(com, expr));
}
auto com_d = divisors(com);
for (auto d: com_d) {
no_discount[d] += 1;
}
}
// for (auto [e, cnt] : edge_count) {
// std::cout << cnt << " edges with len " << e << std::endl;
// }
// std::cout << "live cycles: " << live_cycles << std::endl;
// for (auto [d, cnd] : no_discount) {
// std::cout << "for d = " << d << ", " << cnd << " cycles will not get discount" << std::endl;
// }
for (ll d = 1; d <= n - 1; d++) {
// first we need to count overall number of edges with d | k then apply discounts
ll ans = 0;
for (ll k = d; k <= n; k += d) {
ans += edge_count[k];
}
// std::cout << "overall payment: " << ans << std::endl;
// edge does not pay if it can be plased at the last position
// which is same as the number of participants
// so now the problem is to find the number of cycles containing d, 2*d, 3*d and so on
// or we can
ans -= participants[d].size();
// std::cout << "after discount: " << ans << std::endl;
// ans -= participants[d].size();
// std::cout << "after discount: " << ans << std::endl;
// ans -= (participants[d].size() - no_discount[d]); // then retract the discount for those who marked as no discount
// std::cout << "after discount more: " << ans << std::endl;
std::cout << ans << std::endl;
}
}
int main() {
g_divisor_table.resize(2 * 100'000 + 10);
for (int i = 1; i < g_divisor_table.size(); i++) {
g_divisor_table[i] = divisors(i);
}
int T;
// std::cin >> T;
T = 1;
for (int i = 0; i < T; i++) {
solve();
// std::cout << "==================\n";
}
}// END: b.cpp