結果
問題 | No.2249 GCDistance |
ユーザー |
|
提出日時 | 2023-03-17 23:52:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 520 ms / 5,000 ms |
コード長 | 2,032 bytes |
コンパイル時間 | 2,413 ms |
コンパイル使用メモリ | 196,632 KB |
最終ジャッジ日時 | 2025-02-11 14:36:23 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 10 |
ソースコード
#include <bits/stdc++.h>using namespace std;#ifdef _RUTHEN#include <debug.hpp>#else#define show(...) true#endifusing ll = long long;#define rep(i, n) for (int i = 0; i < (n); i++)template <class T> using V = vector<T>;std::vector<int> totient_table(int n) {std::vector<int> res(n + 1);std::iota(res.begin(), res.end(), 0);for (int p = 2; p <= n; p++) {if (res[p] != p) continue;for (int i = p; i <= n; i += p) {res[i] /= p;res[i] *= p - 1;}}return res;}template <class T> struct CumulativeSum {int n;std::vector<T> seg;CumulativeSum() = default;CumulativeSum(int n) : n(n), seg(n + 1, T(0)) {}CumulativeSum(std::vector<T> &a) {n = (int)a.size();seg.assign(n + 1, T(0));for (int i = 0; i < n; i++) seg[i + 1] = seg[i] + a[i];}// [l, r)T sum(int l, int r) const {assert(0 <= l and l <= r and r <= n);return seg[r] - seg[l];}// A[l] += x, A[l + 1] += x, ... , A[r - 1] += xvoid imos(int l, int r, T x = T(1)) {assert(0 <= l and l <= r and r <= n);seg[l] += x;seg[r] -= x;}void build() {for (int i = 0; i < n; i++) seg[i + 1] += seg[i];}// return A[p]T get(int p) const {assert(0 <= p and p < n);return seg[p];}// outputfriend std::ostream &operator<<(std::ostream &os, const CumulativeSum &A) {os << "n = " << A.n << "\n";for (int i = 0; i <= A.n; i++) os << A.seg[i] << " \n"[i == A.n];return os;}};int main() {ios::sync_with_stdio(false);cin.tie(0);auto ttt = totient_table(10000000);V<long long> tl(10000001);rep(i, 10000001) tl[i] = ttt[i];CumulativeSum<long long> seg(tl);int tt;cin >> tt;while (tt--) {long long N;cin >> N;long long ans = N * (N - 1) - seg.sum(0, N + 1) + 1;cout << ans << '\n';}return 0;}