Luzhiled's Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub ei1333/library

:heavy_check_mark: test/verify/aoj-2286.test.cpp

Depends on

Code

// competitive-verifier: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2286

#include "../../template/template.hpp"

#include "../../math/number-theory/euler-phi-table.hpp"

int main() {
  const int MAX_N = 1000000;
  auto phi = euler_phi_table(MAX_N);
  vector< int64_t > S(MAX_N + 1);
  S[1] = 2;
  for(int i = 2; i <= MAX_N; i++) {
    S[i] = S[i - 1] + phi[i];
  }
  int T;
  cin >> T;
  while(T--) {
    int N;
    cin >> N;
    cout << S[N] << "\n";
  }
}
#line 1 "test/verify/aoj-2286.test.cpp"
// competitive-verifier: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2286

#line 1 "template/template.hpp"
#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

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 <typename T = int64>
vector<T> make_v(size_t a) {
  return vector<T>(a);
}

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
  t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
  for (auto &e : t) fill_v(e, v);
}

template <typename F>
struct FixPoint : F {
  explicit FixPoint(F &&f) : F(forward<F>(f)) {}

  template <typename... Args>
  decltype(auto) operator()(Args &&...args) const {
    return F::operator()(*this, forward<Args>(args)...);
  }
};

template <typename F>
inline decltype(auto) MFP(F &&f) {
  return FixPoint<F>{forward<F>(f)};
}
#line 4 "test/verify/aoj-2286.test.cpp"

#line 1 "math/number-theory/euler-phi-table.hpp"
/**
 * @brief Euler’s Phi Table(オイラーのφ関数テーブル)
 *
 */
vector<int> euler_phi_table(int n) {
  vector<int> euler(n + 1);
  for (int i = 0; i <= n; i++) {
    euler[i] = i;
  }
  for (int i = 2; i <= n; i++) {
    if (euler[i] == i) {
      for (int j = i; j <= n; j += i) {
        euler[j] = euler[j] / i * (i - 1);
      }
    }
  }
  return euler;
}
#line 6 "test/verify/aoj-2286.test.cpp"

int main() {
  const int MAX_N = 1000000;
  auto phi = euler_phi_table(MAX_N);
  vector< int64_t > S(MAX_N + 1);
  S[1] = 2;
  for(int i = 2; i <= MAX_N; i++) {
    S[i] = S[i - 1] + phi[i];
  }
  int T;
  cin >> T;
  while(T--) {
    int N;
    cin >> N;
    cout << S[N] << "\n";
  }
}

Test cases

Env Name Status Elapsed Memory
g++ testcase_00 :heavy_check_mark: AC 18 ms 15 MB
clang++ testcase_00 :heavy_check_mark: AC 17 ms 15 MB
Back to top page