#line 2 "library/KowerKoint/stl-expansion.hpp" #include template std::istream& operator>>(std::istream& is, std::pair& p) { is >> p.first >> p.second; return is; } template std::istream& operator>>(std::istream& is, std::array& a) { for (size_t i = 0; i < N; ++i) { is >> a[i]; } return is; } template std::istream& operator>>(std::istream& is, std::vector& v) { for (auto& e : v) is >> e; return is; } template std::ostream& operator<<(std::ostream& os, const std::pair& p) { os << p.first << " " << p.second; return os; } template std::ostream& operator<<(std::ostream& os, const std::array& a) { for (size_t i = 0; i < N; ++i) { os << a[i] << (i + 1 == a.size() ? "" : " "); } return os; } template std::ostream& operator<<(std::ostream& os, const std::vector& v) { for (size_t i = 0; i < v.size(); ++i) { os << v[i] << (i + 1 == v.size() ? "" : " "); } return os; } #line 3 "library/KowerKoint/base.hpp" using namespace std; #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define END(...) { print(__VA_ARGS__); return; } using VI = vector; using VVI = vector; using VVVI = vector; using ll = long long; using VL = vector; using VVL = vector; using VVVL = vector; using ull = unsigned long long; using VUL = vector; using VVUL = vector; using VVVUL = vector; using VD = vector; using VVD = vector; using VVVD = vector; using VS = vector; using VVS = vector; using VVVS = vector; using VC = vector; using VVC = vector; using VVVC = vector; using P = pair; using VP = vector

; using VVP = vector; using VVVP = vector; using LP = pair; using VLP = vector; using VVLP = vector; using VVVLP = vector; template using PQ = priority_queue; template using GPQ = priority_queue, greater>; constexpr int INF = 1001001001; constexpr ll LINF = 1001001001001001001ll; constexpr int DX[] = {1, 0, -1, 0}; constexpr int DY[] = {0, 1, 0, -1}; void print() { cout << '\n'; } template void print(const T &t) { cout << t << '\n'; } template void print(const Head &head, const Tail &... tail) { cout << head << ' '; print(tail...); } #ifdef DEBUG void dbg() { cerr << '\n'; } template void dbg(const T &t) { cerr << t << '\n'; } template void dbg(const Head &head, const Tail &... tail) { cerr << head << ' '; dbg(tail...); } #else template void dbg(const Args &... args) {} #endif template vector> split(typename vector::const_iterator begin, typename vector::const_iterator end, T val) { vector> res; vector cur; for(auto it = begin; it != end; it++) { if(*it == val) { res.push_back(cur); cur.clear(); } else cur.push_back(*it); } res.push_back(cur); return res; } vector split(typename string::const_iterator begin, typename string::const_iterator end, char val) { vector res; string cur = ""; for(auto it = begin; it != end; it++) { if(*it == val) { res.push_back(cur); cur.clear(); } else cur.push_back(*it); } res.push_back(cur); return res; } template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template pair> compress(const vector &a) { int n = a.size(); vector x; REP(i, n) x.push_back(a[i]); sort(ALL(x)); x.erase(unique(ALL(x)), x.end()); VI res(n); REP(i, n) res[i] = lower_bound(ALL(x), a[i]) - x.begin(); return make_pair(res, x); } template auto rle(It begin, It end) { vector> res; if(begin == end) return res; auto pre = *begin; int num = 1; for(auto it = begin + 1; it != end; it++) { if(pre != *it) { res.emplace_back(pre, num); pre = *it; num = 1; } else num++; } res.emplace_back(pre, num); return res; } template vector> rle_sort(It begin, It end) { vector cloned(begin, end); sort(ALL(cloned)); auto e = rle(ALL(cloned)); sort(ALL(e), [](const auto& l, const auto& r) { return l.second < r.second; }); return e; } template pair, vector> factorial(int n) { vector res(n+1), rev(n+1); res[0] = 1; REP(i, n) res[i+1] = res[i] * (i+1); rev[n] = 1 / res[n]; for(int i = n; i > 0; i--) { rev[i-1] = rev[i] * i; } return make_pair(res, rev); } #line 3 "library/KowerKoint/integer/extgcd.hpp" constexpr ll extgcd(ll a, ll b, ll& x, ll& y) { x = 1, y = 0; ll nx = 0, ny = 1; while(b) { ll q = a / b; ll r = a % b; a = b, b = r; ll nnx = x - q * nx; ll nny = y - q * ny; x = nx, nx = nnx; y = ny, ny = nny; } return a; } #line 3 "library/KowerKoint/integer/pow-mod.hpp" constexpr ll inv_mod(ll n, ll m) { n %= m; if (n < 0) n += m; ll x = -1, y = -1; if(extgcd(n, m, x, y) != 1) throw logic_error(""); x %= m; if(x < 0) x += m; return x; } constexpr ll pow_mod(ll a, ll n, ll m) { if(n == 0) return 1LL; if(n < 0) return inv_mod(pow_mod(a, -n, m), m); a %= m; if (a < 0) n += m; ll res = 1; while(n) { if(n & 1) { res *= a; res %= m; } n >>= 1; a *= a; a %= m; } return res; } #line 3 "library/KowerKoint/algebra/field.hpp" template struct SumGroupBase { constexpr static bool defzero = false; using Coef = nullptr_t; using Scalar = nullptr_t; }; template struct ProdGroupBase { constexpr static bool defone = false; }; template struct RepresentationBase { using R = T; constexpr static T construct(const R& x) { return x; } constexpr static R represent(const T& x) { return x; } }; template struct CompareBase { constexpr static bool eq(const T& x, const T& y) { return x == y; } constexpr static bool lt(const T& x, const T& y) { return x < y; } }; template struct FinitePropertyBase { constexpr static bool is_finite = false; }; template , typename ProdGroup = ProdGroupBase, typename Representation = RepresentationBase, typename Compare = CompareBase, typename FiniteProperty = FinitePropertyBase> struct Field { using R = typename Representation::R; using Coef = typename SumGroup::Coef; using Scalar = typename SumGroup::Scalar; T val; constexpr static Field zero() { return SumGroup::zero; } constexpr static Field one() { return ProdGroup::one; } constexpr static bool defzero = SumGroup::defzero; constexpr static bool defone = ProdGroup::defone; constexpr static bool is_finite = FiniteProperty::is_finite; constexpr Field() { if constexpr(SumGroup::defzero) val = SumGroup::zero; else if constexpr(SumGroup::defone) val = ProdGroup::one; else val = T(); } constexpr Field(const R& r) : val(Representation::construct(r)) {} constexpr R represent() const { return Representation::represent(val); } constexpr decltype(auto) operator[](size_t i) const { return val[i]; } constexpr static Field premitive_root() { return FiniteProperty::premitive_root(); } constexpr static size_t order() { return FiniteProperty::order(); } constexpr Field& operator*=(const Field& other) { ProdGroup::mulassign(val, other.val); return *this; } constexpr Field operator*(const Field& other) const { return Field(*this) *= other; } constexpr Field inv() const { return ProdGroup::inv(val); } constexpr Field& operator/=(const Field& other) { return *this *= other.inv(); } constexpr Field operator/(const Field& other) const { return Field(*this) /= other; } constexpr Field pow(ll n) const { if(n < 0) { return inv().pow(-n); } Field res = one(); Field a = *this; while(n > 0) { if(n & 1) res *= a; a *= a; n >>= 1; } return res; } constexpr Field operator+() const { return *this; } constexpr Field& operator+=(const Field& other) { SumGroup::addassign(val, other.val); return *this; } constexpr Field operator+(const Field& other) const { return Field(*this) += other; } constexpr Field operator-() const { return SumGroup::minus(val); } constexpr Field& operator-=(const Field& other) { return *this += -other; } constexpr Field operator-(const Field& other) const { return Field(*this) -= other; } constexpr Field& operator++() { return *this += one(); } Field operator++(int) { Field ret = *this; ++*this; return ret; } constexpr Field& operator--() { return *this -= one(); } Field operator--(int) { Field ret = *this; --*this; return ret; } constexpr Field& operator*=(const Coef& other) { SumGroup::coefassign(val, other); return *this; } constexpr Field operator*(const Coef& other) const { return Field(*this) *= other; } constexpr Scalar dot(const Field& other) const { return SumGroup::dot(val, other.val); } constexpr Scalar norm() const { return dot(*this); } constexpr bool operator==(const Field& other) const { return Compare::eq(val, other.val); } constexpr bool operator!=(const Field& other) const { return !(*this == other); } constexpr bool operator<(const Field& other) const { return Compare::lt(represent(), other.represent()); } constexpr bool operator>(const Field& other) const { return other < *this; } constexpr bool operator<=(const Field& other) const { return !(*this > other); } constexpr bool operator>=(const Field& other) const { return !(*this < other); } friend istream& operator>>(istream& is, Field& f) { R r; is >> r; f = r; return is; } friend ostream& operator<<(ostream& os, const Field& f) { return os << f.represent(); } }; namespace std { template struct hash> { size_t operator()(const Field& f) const { return hash::R>()(f.represent()); } }; } template struct is_field : false_type {}; template struct is_field> : true_type {}; template constexpr bool is_field_v = is_field::value; template constexpr T zero() { if constexpr(is_field_v) return T::zero(); else return 0; } template constexpr T one() { if constexpr(is_field_v) return T::one(); else return 1; } template constexpr bool is_finite() { if constexpr(is_field_v) return T::is_finite; else return false; } #line 4 "library/KowerKoint/algebra/modint.hpp" template struct SumGroupModint : SumGroupBase { static ll& addassign(ll& l, const ll& r) { ll ret; if(__builtin_add_overflow(l, r, &ret)) { l = l % mod + r % mod; } else { l = ret; } return l; } constexpr static bool defzero = true; constexpr static ll zero = 0; constexpr static ll minus(const ll& x) { return -x; } }; template struct ProdGroupModint : ProdGroupBase { constexpr static bool defmul = true; static ll& mulassign(ll& l, const ll& r) { ll ret; if(__builtin_mul_overflow(l, r, &ret)) { l = (l % mod) * (r % mod); } else { l = ret; } return l; } constexpr static bool defone = true; constexpr static ll one = 1; constexpr static bool definv = true; constexpr static ll inv(const ll& x) { return inv_mod(x, mod); } }; template struct RepresentationModint : RepresentationBase { using R = ll; constexpr static ll construct(const R& x) { return x % mod; } constexpr static R represent(const ll& x) { ll ret = x % mod; if(ret < 0) ret += mod; return ret; } }; template struct CompareModint : CompareBase { constexpr static bool lt(const ll& l, const ll& r) { return RepresentationModint::represent(l) < RepresentationModint::represent(r); } constexpr static bool eq(const ll& l, const ll& r) { return RepresentationModint::represent(l) == RepresentationModint::represent(r); } }; template struct FinitePropertyModint : FinitePropertyBase { constexpr static bool is_finite = true; constexpr static ll premitive_root() { static_assert(mod == 998244353); return 3; } constexpr static size_t order() { return mod - 1; } }; template using Modint = Field, ProdGroupModint, RepresentationModint, CompareModint, FinitePropertyModint>; using MI3 = Modint<998244353>; using V3 = vector; using VV3 = vector; using VVV3 = vector; using MI7 = Modint<1000000007>; using V7 = vector; using VV7 = vector; using VVV7 = vector; #line 3 "library/KowerKoint/counting/counting.hpp" template struct Counting { vector fact, ifact; Counting() {} Counting(ll n) { assert(n >= 0); expand(n); } void expand(ll n) { assert(n >= 0); ll sz = (ll)fact.size(); if(sz > n) return; fact.resize(n+1); ifact.resize(n+1); fact[0] = 1; FOR(i, max(1LL, sz), n+1) fact[i] = fact[i-1] * i; ifact[n] = fact[n].inv(); for(ll i = n-1; i >= sz; i--) ifact[i] = ifact[i+1] * (i+1); } T p(ll n, ll r) { if(n < r) return 0; assert(r >= 0); expand(n); return fact[n] * ifact[n-r]; } T c(ll n, ll r) { if(n < r) return 0; assert(r >= 0); expand(n); return fact[n] * ifact[r] * ifact[n-r]; } T h(ll n, ll r) { assert(n >= 0); assert(r >= 0); return c(n+r-1, r); } T stirling(ll n, ll k) { if(n < k) return 0; assert(k >= 0); if(n == 0) return 1; T res = 0; T sign = k%2? -1 : 1; expand(k); REP(i, k+1) { res += sign * ifact[i] * ifact[k-i] * T(i).pow(n); sign *= -1; } return res; } vector> stirling_table(ll n, ll k) { assert(n >= 0 && k >= 0); vector> res(n+1, vector(k+1)); res[0][0] = 1; FOR(i, 1, n+1) FOR(j, 1, k+1) { res[i][j] = res[i-1][j-1] + j * res[i-1][j]; } return res; } T bell(ll n, ll k) { assert(n >= 0 && k >= 0); expand(k); vector tmp(k+1); T sign = 1; tmp[0] = 1; FOR(i, 1, k+1) { sign *= -1; tmp[i] = tmp[i-1] + sign * ifact[i]; } T res = 0; REP(i, k+1) { res += T(i).pow(n) * ifact[i] * tmp[k-i]; } return res; } vector> partition_table(ll n, ll k) { assert(n >= 0 && k >= 0); vector> res(n+1, vector(k+1)); REP(i, k+1) res[0][i] = 1; FOR(i, 1, n+1) FOR(j, 1, k+1) { res[i][j] = res[i][j-1] + (i= 0; i--) { bool over = false; ull tmp = 1; ull nxt = res | 1ULL << i; REP(i, k) { if(tmp > x / nxt) { over = true; break; } tmp *= nxt; } if(!over) res = nxt; } return res; } #line 2 "library/KowerKoint/bit/bitset.hpp" struct Bitset { private: constexpr static ull mask[] = { 0x0000000000000000ull, 0x0000000000000001ull, 0x0000000000000003ull, 0x0000000000000007ull, 0x000000000000000Full, 0x000000000000001Full, 0x000000000000003Full, 0x000000000000007Full, 0x00000000000000FFull, 0x00000000000001FFull, 0x00000000000003FFull, 0x00000000000007FFull, 0x0000000000000FFFull, 0x0000000000001FFFull, 0x0000000000003FFFull, 0x0000000000007FFFull, 0x000000000000FFFFull, 0x000000000001FFFFull, 0x000000000003FFFFull, 0x000000000007FFFFull, 0x00000000000FFFFFull, 0x00000000001FFFFFull, 0x00000000003FFFFFull, 0x00000000007FFFFFull, 0x0000000000FFFFFFull, 0x0000000001FFFFFFull, 0x0000000003FFFFFFull, 0x0000000007FFFFFFull, 0x000000000FFFFFFFull, 0x000000001FFFFFFFull, 0x000000003FFFFFFFull, 0x000000007FFFFFFFull, 0x00000000FFFFFFFFull, 0x00000001FFFFFFFFull, 0x00000003FFFFFFFFull, 0x00000007FFFFFFFFull, 0x0000000FFFFFFFFFull, 0x0000001FFFFFFFFFull, 0x0000003FFFFFFFFFull, 0x0000007FFFFFFFFFull, 0x000000FFFFFFFFFFull, 0x000001FFFFFFFFFFull, 0x000003FFFFFFFFFFull, 0x000007FFFFFFFFFFull, 0x00000FFFFFFFFFFFull, 0x00001FFFFFFFFFFFull, 0x00003FFFFFFFFFFFull, 0x00007FFFFFFFFFFFull, 0x0000FFFFFFFFFFFFull, 0x0001FFFFFFFFFFFFull, 0x0003FFFFFFFFFFFFull, 0x0007FFFFFFFFFFFFull, 0x000FFFFFFFFFFFFFull, 0x001FFFFFFFFFFFFFull, 0x003FFFFFFFFFFFFFull, 0x007FFFFFFFFFFFFFull, 0x00FFFFFFFFFFFFFFull, 0x01FFFFFFFFFFFFFFull, 0x03FFFFFFFFFFFFFFull, 0x07FFFFFFFFFFFFFFull, 0x0FFFFFFFFFFFFFFFull, 0x1FFFFFFFFFFFFFFFull, 0x3FFFFFFFFFFFFFFFull, 0x7FFFFFFFFFFFFFFFull, 0xFFFFFFFFFFFFFFFFull }; void correct() { if(n % 64) v[bnum-1] &= mask[n % 64]; } public: vector v; int n, bnum; Bitset(int n_ = 0) : n(n_) { assert(n_ >= 0); bnum = (n+63) / 64; v.resize(bnum); } int operator[](int i) const { assert(0 <= i && i < n); return (v[i/64] >> (i%64)) & 1; } int count() const { int c = 0; for (int i = 0; i < v.size(); i++) { c += __builtin_popcountll(v[i]); } return c; } // not tested int count_range(int l, int r) const { assert(0 <= l && l <= r && r <= n); int c = 0; int l2 = l / 64; int r2 = r / 64; for(int i = l2; i < r2; i++) { c += __builtin_popcountll(v[i]); } if(l % 64) { c -= __builtin_popcountll(v[l2] & mask[l % 64]); } if(r % 64) { c += __builtin_popcountll(v[r2] & mask[r % 64]); } return c; } bool all() const { return count() == n; } bool any() const { return count() > 0; } bool none() const { return count() == 0; } void set(int i) { assert(0 <= i && i < n); v[i / 64] |= 1ull << (i % 64); } void reset(int i) { assert(0 <= i && i < n); v[i / 64] &= ~(1ull << (i % 64)); } void flip(int i) { assert(0 <= i && i < n); v[i / 64] ^= 1ull << (i % 64); } void resize(int n_) { assert(n_ >= 0); n = n_; bnum = (n+63) / 64; v.resize(bnum); correct(); } void all_set() { fill(v.begin(), v.end(), ~0ULL); correct(); } void all_reset() { fill(v.begin(), v.end(), 0); } void all_flip() { for (int i = 0; i < v.size(); i++) { v[i] = ~v[i]; } correct(); } Bitset& operator&=(const Bitset& b) { assert(n == b.n); for(int i = 0; i < min(bnum, b.bnum); i++) { v[i] &= b.v[i]; } return *this; } Bitset operator&(const Bitset& b) const { assert(n == b.n); return Bitset(*this) &= b; } Bitset& operator|=(const Bitset& b) { assert(n == b.n); for(int i = 0; i < min(bnum, b.bnum); i++) { v[i] |= b.v[i]; } correct(); return *this; } Bitset operator|(const Bitset& b) const { assert(n == b.n); return Bitset(*this) |= b; } Bitset& operator^=(const Bitset& b) { assert(n == b.n); for(int i = 0; i < min(bnum, b.bnum); i++) { v[i] ^= b.v[i]; } correct(); return *this; } Bitset operator^(const Bitset& b) const { assert(n == b.n); return Bitset(*this) ^= b; } Bitset operator~() const { Bitset b(*this); b.all_flip(); return b; } bool operator==(const Bitset& b) const { assert(n == b.n); return v == b.v; } bool operator!=(const Bitset& b) const { assert(n == b.n); return v != b.v; } Bitset& operator<<=(int sz) { assert(sz >= 0); for(int i = bnum-1; i >= 0; i--) { if(i-sz/64 < 0) v[i] = 0; else if(i-sz/64-1 < 0 || sz%64 == 0) v[i] = v[i-sz/64] << (sz%64); else v[i] = (v[i-sz/64] << (sz%64)) | (v[i-sz/64-1] >> (64-sz%64)); } correct(); return *this; } Bitset operator<<(int sz) const { assert(sz >= 0); return Bitset(*this) <<= sz; } Bitset& operator>>=(int sz) { assert(sz >= 0); for(int i = 0; i < bnum; i++) { if(i+sz/64 < bnum) v[i] = v[i+sz/64] >> (sz%64); if(i+sz/64+1 < bnum) v[i] |= v[i+sz/64+1] << (64-sz%64); } return *this; } Bitset operator>>(int sz) const { assert(sz >= 0); return Bitset(*this) >>= sz; } }; #line 4 "library/KowerKoint/integer/prime.hpp" struct Prime { Bitset sieved; VI primes; Prime() {} Prime(int n) { assert(n >= 0); expand(n); } void expand(int n) { assert(n >= 0); int sz = (int)sieved.n - 1; if(n <= sz) return; sieved.resize(n+1); sieved.set(0); sieved.set(1); primes.clear(); if(n >= 2) primes.push_back(2); for(int d = 3; d <= n; d += 2) { if(!sieved[d]) { primes.push_back(d); for(ll i = (ll)d*d; i <= n; i += d*2) sieved.set(i); } } } bool is_prime(ull n) { assert(n > 0); if(n == 2) return true; if(!(n & 1)) return false; if(n+1 <= (ull)sieved.n) return !sieved[n]; for(ull d = 2; d*d <= n; d++) { if(n % d == 0) return false; } return true; } VI prime_list(int n) { assert(n > 0); expand(n); return VI(primes.begin(), upper_bound(ALL(primes), n)); } vector> prime_factor(ull n) { assert(n > 0); vector> factor; expand(kth_root_integer(n, 2)); for(ull prime : primes) { if(prime * prime > n) break; int cnt = 0; while(n % prime == 0) { n /= prime; cnt++; } if(cnt) factor.emplace_back(prime, cnt); } if(n > 1) factor.emplace_back(n, 1); return factor; } VUL divisor(ull n) { assert(n > 0); auto factor = prime_factor(n); VUL res = {1}; for(auto [prime, cnt] : factor) { int sz = res.size(); res.resize(sz * (cnt+1)); REP(i, sz*cnt) res[sz+i] = res[i] * prime; REP(i, cnt) inplace_merge(res.begin(), res.begin() + sz*(i+1), res.begin() + sz*(i+2)); } return res; } }; #line 3 "Contests/yukicoder_381/yukicoder_381_d/main.cpp" /* #include */ /* using namespace atcoder; */ /* #include "KowerKoint/expansion/ac-library/all.hpp" */ void solve(){ int max_n = 10000000; Prime pr(max_n); VI prime_list = pr.prime_list(max_n); VI totient(max_n+1); for(int i =1; i <= max_n; i++) { totient[i] = i; int x = i; for(int j = 0; j < prime_list.size() && prime_list[j] * prime_list[j] <= x; j++) { if(x % prime_list[j] == 0) { totient[i] = totient[i] / prime_list[j] * (prime_list[j] - 1); while(x % prime_list[j] == 0) x /= prime_list[j]; } } if(x > 1) totient[i] = totient[i] / x * (x - 1); } VL totient_sum(ALL(totient)); REP(i, max_n) totient_sum[i+1] += totient_sum[i]; int t; cin >> t; while(t--) { ll n; cin >> n; print(n*(n-1) - totient_sum[n]+1); } } // generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator) int main() { // Fasterize input/output script ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(100); // scanf/printf user should delete this fasterize input/output script int t = 1; //cin >> t; // comment out if solving multi testcase for(int testCase = 1;testCase <= t;++testCase){ solve(); } return 0; }