Problem:
Problem F: Farey Sequence
slipは数字を眺めるのが好きである。
ファイルをダウンロードしているときの、残り時間を眺めているだけで、時間を潰せるほどである。
そんなslipが友人から面白い数列を教えられた。
その数列の定義は以下のとおりである。
一般項を
F
n
と表わす。
F
n
とは、
n
以下の分母を持つ0以上1以下のすべての約分された分数(既約分数)を小さな順から並べたものである。
ただし、整数0、1はそれぞれ分数0/1、1/1として扱われる。
つまり
F
3
は、
F
3
= (0/1, 1/3, 1/2, 2/3, 1/1)
のように表される。
F
5
であれば
F
5
= (0/1, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 1/1)
と表される。
slipはこの数列にすぐにのめり込んだ。
しかしこの数列を眺めていても、なかなか特徴がつかめなかった。
特徴をつかむためにまずは各項の項数がいくつあるのか調べようと思ったが、
増え方の規則がわからず、自力で理解することを断念した。
そこで、
勝手に友人と思っているあなたに、指定した項にどれだけの項数があるのかを聞くことにした。
あなたの仕事は、与えられた項における項数を求めることである。
Input
入力は以下の形式で与えられる。
t
n
1
...
n
i
...
n
t
t
(
1 ≤ t ≤ 10000
)はテストケースの数である。
n
i
(
1 ≤ n
i
≤ 1000000
)は与えられた項の番号である。
Output
各テストケースごとに、項数を1行に表示せよ。
Sample Input
2
3
5
Output for Sample Input
5
11

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vstr = vector<string>;
using vchar = vector<char>;
using vvchar = vector<vector<char>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vvvb = vector<vector<vector<bool>>>;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<pair<int,ll>>>;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

#define rep(i, a, b) for(ll i = (ll)a; i < (ll)b; i++)
#define REP(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rrep(i, a, b) for(ll i = (ll)b-1; i >= (ll)a; i--)
#define RREP(i, a, b) for(ll i = (ll)b; i >= (ll)a; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YESNO(flag) cout << (flag ? "Yes" : "No") << "\n"
#define spa " "
#define mint modint

const int inf = 1070000000;
const long long INF = 4500000000000000000;
//const long long MOD = 998244353;
const long long MOD = 1000000007;
const double pi = 3.141592653589793238;
const double eps = (1e-10);
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";

template<typename T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename S, typename T> pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    pair<S, T> ans;
    ans.first = a.first + b.first;
    ans.second = a.second + b.second;
    return ans;
} 

//拡張ユークリッド
ll ext_gcd(ll a, ll b, ll &x, ll &y) {
    if(b == 0) {
        x = 1, y = 0;
        return a;
    }

    ll q = a/b;
    ll g = ext_gcd(b, a-q*b, x, y);
    ll z = x-q*y;
    x = y, y = z;
    return g;
}
//mod mにおけるaの逆元. aとmは互いに素.
ll inverse(ll a, ll m) {
    ll x, y;
    ext_gcd(a, m, x, y);
    x = (x+m) % m;
    return x;
}
//modint
template<std::uint_fast64_t mod> struct modint {
    using u64 = std::uint_fast64_t;
    u64 val;

    modint(u64 v = 0) : val(v % mod) {}

    bool operator==(modint other) {
        return val == other.val;
    }
    modint operator+(modint other) {
        modint<mod> ans;
        ans.val = val + other.val;
        if(ans.val >= mod) ans.val -= mod;
        return ans;
    }
    modint operator-(modint other) {
        modint<mod> ans;
        if(val < other.val) val += mod;
        ans.val = val - other.val;
        return ans;
    }
    modint operator*(modint other) {
        modint<mod> ans;
        ans.val = (val * other.val) % mod;
        return ans;
    }
    modint operator/(modint other) {
        modint<mod> ans;
        ans.val = (val * inverse(other.val, mod)) % mod;
        return ans;
    }
    modint &operator+=(modint other) {
        *this = *this + other;
        return *this;
    }
    modint &operator-=(modint other) {
        *this = *this - other;
        return *this;
    }
    modint &operator*=(modint other) {
        *this = *this * other;
        return *this;
    }
    modint &operator/=(modint other) {
        *this = *this / other;
        return *this;
    }
    modint &operator++() {
        *this += 1;
        return *this;
    }
    modint &operator++(int) {
        ++(*this);
        return *this;
    }
    modint &operator--() {
        *this -= 1;
        return *this;
    }
    modint &operator--(int) {
        --(*this);
        return *this;
    }
};
//modintの入出力
template<std::uint_fast64_t mod> std::ostream& operator<<(std::ostream &os, const modint<mod> &x) {
    // modint の 'val' メンバを出力ストリーム(os)に渡す
    os << x.val;
    return os; // ストリームを返す (チェーンのため)
}
template<std::uint_fast64_t mod> std::istream& operator>>(std::istream& is, modint<mod> &x) {
    // modintが内部で使っているu64型を取得
    using u64 = typename modint<mod>::u64; 
    
    u64 input_value;
    is >> input_value; // (1) istream(cin) から一時変数に値を読み込む
    
    // (2) 読み込んだ値を使って modint を再構築する
    //     modintのコンストラクタが (input_value % mod) を処理してくれる
    x = modint<mod>(input_value); 
    
    return is; // (3) ストリームを返す (チェーンのため)
}
//累乗, x^n
template<typename T> T pow(T x, int n) {
    T ans = 1;
    while(n > 0) {
        if(n & 1) ans *= x;
        x *= x;
        n >>= 1; 
    }
    return ans;
}
//階乗, n!
template<typename T> T fact(T n) {
    if(n == 0) return 1;
    return n * fact(n-1);
}
//nPk
template<typename T> T perm(T n, T k) {
    if(k == 0) return 1;
    return n * perm(n-1, k-1);
}
//nCk
template<typename T> T comb(T n, T k) {
    if(k > n) return 0;
    return perm(n, min(k, n-k))/fact(min(k, n-k));
}
//ord(n)
ll ord(ll n, ll p) {
    int ans = 0;
    while(n % p == 0) {
        n /= p;
        ans++;
    }
    return ans;
}
//ルジャンドルの公式ord(n!)
ll factord(ll n, ll p) {
    ll ans = 0;
    ll q = p, tmp = n;
    while(tmp > 0) {
        tmp = n/q;
        ans += tmp;
        q *= p;
    }
    return ans;
}
//素因数分解, O(√N)
vector<pair<ll,ll>> factorize(ll N) {
    vector<pair<ll,ll>> ans;
    for(ll p = 2; p*p <= N; p++) {
        int ex = 0;
        while(N % p == 0) {
            N /= p;
            ex++;
        }
        if(ex != 0) ans.push_back({p,ex});
    }
    if(N != 1) ans.push_back({N,1});
    return ans;
}
//素数判定
bool isprime(long long x) {
    if(x == 1) return false;
    
    for(long long i = 2; i*i <= x; i++) {
        if(x % i == 0) return false;
    }
    return true;
}
//エラトステネスの篩
struct Eratosthenes {
    vector<bool> prime;
    vector<int> minfactor;
    vector<int> mobius;
    vector<ll> euler;

    //コンストラクタ O(NloglogN)
    Eratosthenes(int N) : prime(N+1, true),
                          minfactor(N+1, -1),
                          mobius(N+1, 1),
                          euler(N+1, 1) {
        prime[0] = false;
        prime[1] = false;
        minfactor[1] = 1;
        REP(i,1,N) euler[i] = i;

        for(int p = 2; p <= N; p++) {
            if(!prime[p]) continue;

            minfactor[p] = p;
            mobius[p] = -1;
            euler[p] = p-1;

            for(int q = 2; p*q <= N; q++) {
                prime[p*q] = false;
                if(minfactor[p*q] == -1) minfactor[p*q] = p;
                if(q % p == 0) mobius[p*q] = 0;
                else mobius[p*q] *= -1;
                euler[p*q] = euler[p*q]*(p-1)/p;
            }
        }
    }

    //素因数分解 O(logn)
    vector<pair<int,int>> factorize(int n) {
        vector<pair<int,int>> ans;
        while(n > 1) {
            int p = minfactor[n], exp = 0;
            while(n % p == 0) {
                n /= p;
                exp++;
            }
            ans.push_back({p, exp});
        }
        return ans;
    }
    //約数列挙 O(σ(n))
    vector<int> divisors(int n) {
        vector<int> ans = {1};
        while(n > 1) {
            int p = minfactor[n], d = 1, s = ans.size();
            while(n % p == 0) {
                d *= p;
                for(int i = 0; i < s; i++) {
                    ans.push_back(ans[i]*d);
                }
                n /= p;
            }
        }
        return ans;
    }
};
//高速ゼータ変換
template<typename T> void fast_zeta(vector<T> &f) {
    int N = f.size();
    Eratosthenes sieve(N);
    for(int p = 2; p < N; p++) {
        if(!sieve.prime[p]) continue;
        
        for(int k = N/p; k >= 1; k--) {
            f[k] += f[k*p];
        }
    }
}
//高速メビウス変換
template<typename T> void fast_mobius(vector<T> &F) {
    int N = F.size();
    Eratosthenes sieve(N);
    for(int p = 2; p < N; p++) {
        if(!sieve.prime[p]) continue;

        for(int k = 1; k*p < N; k++) {
            F[k] -= F[k*p];
        }
    }
}
//添字GCD畳み込み
template<typename T> vector<T> gcd_conv(vector<T> &f, vector<T> &g) {
    int N = max(f.size(), g.size());
    vector<T> F(N, 0), G(N, 0), H(N);
    for(int i = 0; i < f.size(); i++) F[i] = f[i];
    for(int i = 0; i < g.size(); i++) G[i] = g[i];
    fast_zeta(F);
    fast_zeta(G);
    
    for(int i = 0; i < N; i++) H[i] = F[i]*G[i];
    fast_mobius(H);
    
    return H;
}

//行列積
vvll matrix_product(vvll A, vvll B) {
    int H = A.size(), W = A[0].size(), S = B.size(), T = B[0].size();
    if(W != S) {
        cout << "matrix_size_error" << "\n";
        return vvll(0);
    }

    vvll C(H, vll(T, 0));
    rep(i,0,H) rep(j,0,T) {
        rep(k,0,W) {
            C[i][j] += A[i][k]*B[k][j];
            //C[i][j] %= M;
        }
    }
    return C;
}
vvll matrix_pow(vvll A, ll n) {
    int N = A.size();
    vvll ans(N, vll(N, 0));
    rep(i,0,N) ans[i][i] = 1;
    
    while(n > 0) {
        if(n & 1) ans = matrix_product(ans, A);
        A = matrix_product(A, A);
        n >>= 1; 
    }
    return ans;
}

//1+2+...+n = n(n+1)/2
ll tri(ll n) {
    ll x = n*(n+1);
    return x/2;
}

//座標圧縮
vector<int> compress(vector<int> A) {
    vector<int> B = A;

    sort(B.begin(), B.end());
    B.erase(unique(B.begin(), B.end()), B.end());

    vector<int> res(A.size());
    for(int i = 0; i < (int)A.size(); i++) {
        res[i] = lower_bound(B.begin(), B.end(), A[i]) - B.begin();
    }
    return res;
}

//正方形グリッドの右回転, 左回転
void rotate_right(vector<vector<char>> &S) {
    int N = S.size();
    auto T = S;
    rep(i,0,N) rep(j,0,N) {
        T[i][j] = S[N-1-j][i];
    }
    S = T;
}
void rotate_left(vector<vector<char>> &S) {
    int N = S.size();
    auto T = S;
    rep(i,0,N) rep(j,0,N) {
        T[i][j] = S[j][N-1-i];
    }
    S = T;
}

//2点(a,b)と(x,y)の距離
long double dist(pair<long double, long double> a, pair<long double, long double> b) {
    return sqrt((a.first-b.first)*(a.first-b.first) + (a.second-b.second)*(a.second-b.second));
}
long double man(pair<long double, long double> a, pair<long double, long double> b) {
    return abs(a.first-b.first) + abs(a.second-b.second);
}
//内分点
pair<long double, long double> internal_division(pair<long double, long double> a, pair<long double, long double> b, long double p) {
    long double x = a.first + (b.first - a.first) * p;
    long double y = a.second + (b.second - a.second) * p;
    return {x, y};
}

//桁数
int digit(ll N) {
    if(N <= 9) return 1;

    return 1 + digit(N / 10);
}
//A進数文字列NをB進数に変換. A,Bは10以下
string base_change(string N, ll A, ll B) {
    ll X = stoll(N), Y = 0;

    ll i = 1;
    while(X != 0) {
        Y += (X % 10) * i;
        i *= A;
        X /= 10;
    }

    X = Y, Y = 0;
    i = 1;
    while(X != 0) {
        Y += (X % B) * i;
        i *= 10;
        X /= B;
    }

    return to_string(Y);
}
//回文判定
bool palin(string S) {
    rep(i,0,S.size()) {
        if(S[i] != S[S.size()-1-i]) return false;
    }
    return true;
}

//hh:mm:ss to second
int convert_to_time(string S) {
    ll h = 10*(S[0]-'0') + (S[1]-'0');
    ll m = 10*(S[3]-'0') + (S[4]-'0');
    ll s = 10*(S[6]-'0') + (S[7]-'0');
    
    return h*3600+m*60+s;
}

//DFS
void dfs(const Graph &G, int v, vector<bool> &seen) { 
    seen[v] = true;
    
    for (auto next_v : G[v]) { 
        if (!seen[next_v]) {
            dfs(G, next_v, seen);
        }
    }
}
void griddfs(const vector<vector<char>> &G, int x, int y, vector<vector<bool>> &seen) {
    int H = G.size(), W = G[0].size();
    seen[x][y] = true;
    
    for (int i = 0; i < 8; i++) { 
        int nx = x + dx[i], ny = y + dy[i];
        if(nx < 0 or nx >= H or ny < 0 or ny >= W) continue;
        if (!seen[nx][ny] and G[nx][ny] != '#') griddfs(G, nx, ny, seen);
    }
}
//BFS
void bfs(const Graph &G, int v, vector<int> &dist) {
    rep(i,0,dist.size()) dist[i] = inf;
    dist[v] = 0;
    queue<int> q;
    q.push(v);
    while(!q.empty()) {
        int u = q.front();
        q.pop();
        for(auto next_u : G[u]) {
            if(dist[next_u] == inf) {
                dist[next_u] = dist[u] + 1;
                q.push(next_u);
            }
        }
    }
}
void gridbfs(const vector<vector<char>> &G, int x, int y, vector<vector<int>> &dist) {
    int H = G.size(), W = G[0].size();
    dist[x][y] = 0;
    queue<pair<int, int>> q;
    q.push(make_pair(x, y));
    while(!q.empty()) {
        int x = q.front().first, y = q.front().second;
        q.pop();
        for(int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx < 0 or nx >= H or ny < 0 or ny >= W) continue;
            if(dist[nx][ny] == inf and G[nx][ny] != '#') {
                dist[nx][ny] = dist[x][y] + 1;
                q.push(make_pair(nx, ny));
            }
        }
    }
}
//ワーシャル・フロイド
vector<vector<ll>> floyd(vector<vector<ll>> G) {
    int N = G.size();
    auto dp = G;
    for (int k = 0; k < N; k++){
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if(dp[i][j] > dp[i][k] + dp[k][j] and dp[i][k] != INF and dp[k][j] != INF) {
                    dp[i][j] = dp[i][k] + dp[k][j];
                }
            }
        }
    }
    return dp;
}
//サイクルがあるか判定
bool cycle(const Graph &G, int v, vector<bool> &seen,  vector<bool> &finished) {
    seen[v] = true;    // 行きがけ時に true になる
    for (auto v2 : G[v]) {
        //if (v2 が逆戻りの場合) continue;  // 無向グラフの場合は必要

        // 頂点 v2 がすでに探索済みの場合はスキップ 
        if (finished[v2]) continue;

        // サイクル検出
        if (seen[v2] && !finished[v2]) return true;

        // 頂点 v2 を再帰的に探索
        if (cycle(G, v2, seen, finished)) return true;
    }
    finished[v] = true;  // 帰りがけ時に true になる
    return false;
}

//Union-Find
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
    
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
    
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

void solve() {
}

int main() {
    int t; cin >> t;
    Eratosthenes sieve(1000000);
    vll phi(1000001, 1);
    REP(i,1,1000000) {
        phi[i] = phi[i-1]+sieve.euler[i];
    }
    while(t--) {
        int n; cin >> n;
        cout << phi[n] << "\n";
    }

    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 26504
final_rank: 15

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include<sstream>
#include<list>
#include<iomanip>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <bitset>
#include <cassert>
#include <stdlib.h>
#include <stdio.h>
#include <random>
#include <chrono>
using namespace std;
const long long LINF = 3e18 + 7;
const int MAX_N = 5000010;
const int MAX_W = 1000010;
const int MAX_ARRAYK = 100000;
double PI = 3.14159265358979323846;
const int INF = 2147483647;
//using ll = long long;

// Farey Sequence
// AOJ 2286
// https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2286
// https://ncastar.hatenablog.com/entry/20140320/1395323746
// https://qiita.com/hidekikangeki/items/e2524f199ae1d483f060
// 包除原理、オイラーのφ関数
// https://nanikaka.hatenadiary.org/entry/20111224/1324690802

long long euler[MAX_N];
long long answer[MAX_N];
void euler_phi2() {
	for (long long i = 0; i < MAX_N; i++) {
		euler[i] = i;
	}
	for (long long i = 2; i < MAX_N; i++) {
		if (euler[i] == i) {
			for (long long j = i; j < MAX_N; j += i) {
				euler[j] = euler[j] / i * (i - 1);
			}
		}
	}
}


int main() {

	
	// Farey Sequence
	euler_phi2();
	answer[1] = 2;
	for (long long i = 2; i < MAX_N; i++) {
		answer[i] = answer[i - 1] + euler[i];
	}
	int T, M;
	cin >> T;
	for (int t = 0; t < T; t++) {
		cin >> M;
		cout << answer[M] << endl;
	}


	return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 81456
final_rank: 19

code_snippet: // #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

using ll=long long;
using ld=long double;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vl=vector<ll>;
using vvl=vector<vl>;

#define rep(i,n) for(long long i=0LL;i<n;i++)
#define rrep(i,a,b) for(long long i=a;i>=b;i--)
#define FOR(i,k,n) for(long long i=k;i<n;i++)
#define ALL(v) v.begin(),v.end()
template<typename T>ostream&operator<<(ostream& os,vector<T>&v){for(int i = 0;i < int(size(v));i++)os << v[i] << (i+1==int(size(v))?"":" ");return os;}
template<typename T>istream&operator>>(istream& is,vector<T>&v){for(auto &in : v)is >> in;return is;}
ll INF = (1LL << 60) - 6846976;
/* INF = (1LL << 60) - 6846976*/


// #include<atcoder/all> 
// using namespace atcoder;
// using mint = modint998244353;ll mod = 998244353;
// // using mint = modint1000000007;ll mod = 1000000007;
// //using mint = modint;
// using vm = vector<mint>;
// using vvm = vector<vm>;
// ostream&operator<<(ostream& os,vector<mint>&v){for(int i = 0;i < int(size(v));i++)os << v[i].val() << (i+1==int(size(v))?"":" ");return os;}

#define LB(A,x) int(lower_bound(ALL(A),x)-A.begin())


// vl dx = {1,0,-1,0}, dy = {0,1,0,-1};
// vl dx = {1,1,1,0,-1,-1,-1,0},dy={-1,0,1,1,-1,0,1,-1};
//----------------------------------------------

int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);cout<<fixed<<setprecision(15);
//==============================================
  ll T;
  cin>>T;
  ll MAX_N=1000009;
  vector<ll> phi(MAX_N);
  iota(ALL(phi),0LL);
  vector<bool> is_prime(MAX_N,1);
  for(int p=2;p<MAX_N;p++) if(is_prime[p]){
    phi[p]/=p;
    phi[p]*=p-1;
    for(int nx=2*p;nx<=MAX_N;nx+=p){
      is_prime[nx]=0;
      phi[nx]/=p;
      phi[nx]*=p-1;
    }
  }

  rep(i,MAX_N-1) phi[i+1]+=phi[i];

  while(T--){
    ll N; cin>>N;
    cout << phi[N]+1<<endl;

  }

}
accuracy: 1
time_ms: 20
memory_kb: 11128
final_rank: 1

code_snippet: #include <iostream>
#include <cstdint>
#include <vector>

using namespace std;

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	uint16_t t, i;
	uint32_t n[10000];
	cin >> t;
	for (i = 0; i != t; ++i) cin >> n[i];

	vector<uint64_t> ans(1'000'001), ex(1'000'001, 1);
	ans[0] = 0, ans[1] = 2;
	for (uint32_t i = 2; i <= 1'000'000; ++i)
	{
		ans[i] = ans[i - 1] + (i - ex[i]);
		for (uint32_t j = i * 2; j <= 1'000'000; j += i)
			ex[j] += i - ex[i];
	}

	for (i = 0; i != t; ++i)
		cout << ans[n[i]] << '\n';
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 18660
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

// エラトステネスの篩
vector<bool> Erame(vector<vector<int>> &prs,int N) {
    vector<bool> isprime(N+1, true);
    prs.resize(N+1);
    isprime[1] = false;
    for (int p = 2; p <= N; ++p) {
        if (!isprime[p]) continue;
        prs[p].push_back(p);
        for (int q = p * 2; q <= N; q += p) {
            isprime[q] = false;
            prs[q].push_back(p);
        }
    }
    return isprime;
}



int main() {
  
  int m=1000000;
  vector<vector<int>> prs;
  vector<bool> pr=Erame(prs,m);
  
  //オイラー数追加
  vector<ll> sphi(m+1);
  sphi[1]=2;
  for(int i=2;i<=m;i++){
    int phi=i;
    for(int j=0;j<(int)prs[i].size();j++){
      phi=phi/prs[i][j]*(prs[i][j]-1);
    }
    sphi[i]=sphi[i-1]+phi;
  }
  //cout << sphi[1000000] << endl;

  int t,n;
  cin >> t;
  for(int k=0;k<t;k++){
    cin >> n;
    cout << sphi[n] << endl;    
  }

}
accuracy: 1
time_ms: 180
memory_kb: 66060
final_rank: 18

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

const int N = 1000005;
bool not_prime[N];
ll phi[N];

void make_phi() {
    not_prime[0] = not_prime[1] = true;
    for (int i = 1; i < N; ++i) {
        phi[i] = i;
    }
    for (int i = 2; i < N; ++i) {
        if (!not_prime[i]) {
            phi[i] = i - 1;
            for (int j = i + i; j < N; j += i) {
                not_prime[j] = true;
                phi[j] -= phi[j] / i;
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    make_phi();
    for (int i = 1; i < N; ++i) {
        phi[i] += phi[i - 1];
    }
    int q;
    cin >> q;
    while (q--) {
        int n;
        cin >> n;
        cout << phi[n]+1 << "\n";
    }
}
accuracy: 1
time_ms: 20
memory_kb: 12084
final_rank: 2

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#if USE_MP
#include <boost/multiprecision/cpp_int.hpp>
#endif
#include <cassert>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <bitset>
#include <string.h>
#include <numeric>
#include <random>
#if defined _DEBUG
//#include "TestCase.h"
//#include "Util.h"
#endif

using namespace std;

using ll = long long;
using ull = unsigned long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;

using ai2 = array<int, 2>;
using ai3 = array<int, 3>;
using ai4 = array<int, 4>;
using al2 = array<ll, 2>;
using al3 = array<ll, 3>;
using al4 = array<ll, 4>;
using ad2 = array<double, 2>;
using ad3 = array<double, 3>;
using ad4 = array<double, 4>;

inline void Yes(bool upper = false) { cout << (upper ? "YES" : "Yes") << "\n"; }
inline void No(bool upper = false) { cout << (upper ? "NO" : "No") << "\n"; }

inline ll DivCeil(ll nume, ll deno)
{
	assert(deno != 0);
	if (deno < 0) { nume = -nume; deno = -deno; }
	if (nume < 0) return -(-nume / deno);
	else return (nume + deno - 1) / deno;
}
inline ll DivFloor(ll nume, ll deno)
{
	assert(deno != 0);
	if (deno < 0) { nume = -nume; deno = -deno; }
	if (nume < 0) return -((-nume + deno - 1) / deno);
	else return nume / deno;
}
inline ll DivRound(ll nume, ll deno)
{
	assert(deno != 0);
	if (deno < 0) { nume = -nume; deno = -deno; }
	if (nume < 0) return -((-nume + deno / 2) / deno);
	else return (nume + deno / 2) / deno;
}

template <typename T, int S>
auto MakeVecImpl(queue<int>& size, const T& ini)
{
	if constexpr (S == 1)
	{
		return vector<T>(size.front(), ini);
	}
	else
	{
		int fsize = size.front();
		size.pop();
		return vector(fsize, MakeVecImpl<T, S - 1>(size, ini));
	}
}

template <typename T, int S>
auto MakeVec(const array<int, S>& size, const T ini = T())
{
	queue<int> qsize;
	for (const auto v : size) qsize.push(v);
	return MakeVecImpl<T, S>(qsize, ini);
}
int d4[][2] =
{
	{0,-1},
	{0,1},
	{-1,0},
	{1,0},
};
int d8[][2] =
{
	{-1,-1},
	{0,-1},
	{1,-1},

	{-1,0},
	{1,0},

	{-1,1},
	{0,1},
	{1,1},
};
vector<array<int, 2>> Neighbor4(int y, int x)
{
	vector<array<int, 2>> ret;
	ret.push_back({ y, x - 1 });
	ret.push_back({ y, x + 1 });
	ret.push_back({ y - 1, x });
	ret.push_back({ y + 1, x });
	return ret;
}
vector<array<int, 2>> Neighbor6(int y, int x)
{
	vector<array<int, 2>> ret;
	const int ofs = (y & 1); // 1 - (y & 1); //

	ret.push_back({ y, x - 1 });
	ret.push_back({ y, x + 1 });

	ret.push_back({ y - 1, x - 1 + ofs });
	ret.push_back({ y - 1, x + ofs });

	ret.push_back({ y + 1, x - 1 + ofs });
	ret.push_back({ y + 1, x + ofs });

	return ret;
}
vector<array<int, 2>> Neighbor8(int y, int x)
{
	vector<array<int, 2>> ret;
	ret.push_back({ y - 1, x - 1 });
	ret.push_back({ y - 1, x });
	ret.push_back({ y - 1, x + 1 });

	ret.push_back({ y, x - 1 });
	ret.push_back({ y, x + 1 });

	ret.push_back({ y + 1, x - 1 });
	ret.push_back({ y + 1, x });
	ret.push_back({ y + 1, x + 1 });
	return ret;
}

vector<int> DecompDigit(ull val)
{
	if (val == 0)
		return { 0 };

	vector<int> ret;
	while (val)
	{
		ret.emplace_back(val % 10);
		val /= 10;
	}
	reverse(ret.begin(), ret.end());
	return ret;
}


#define PI 3.14159265358979l
long double R2D = 180 / PI;
long double D2R = PI / 180;

static const ll Mod = 1000000007;
static const ll Mod9 = 998244353;// 1000000007;
static const ll INF64 = 4500000000000000000;// 10000000000000000;
static const int INF32 = 2000000000;

random_device rd;
mt19937 mt(0);//(rd());
#if USE_MP
using mpint = boost::multiprecision::cpp_int;
#endif

const double EPS = 1e-10;

vector<bool> isPrime;		// 素数
vector<int> prime;			// 素数
vector<int> minPF;			// 約数である最小の素数
vector<int> phi;			// オイラーのφ関数
vector<int> mobius;			// メビウス関数
vector<ll> phiSum{ 0 };
void Eratosthenes(int SIZE=1e6)
{
	isPrime.resize(SIZE, true);
	minPF.resize(SIZE); iota(minPF.begin(), minPF.end(), 0);
	phi.resize(SIZE); iota(phi.begin(), phi.end(), 0);
	mobius.resize(SIZE, 1);

	isPrime[0] = isPrime[1] = false;

	// 素因数
	for (int i = 2; i < SIZE; i++) {
		if (!isPrime[i]) continue;
		prime.emplace_back(i);
		for (int j = i + i; j < SIZE; j += i) {
			isPrime[j] = false;
			minPF[j] = min(minPF[j], i);
		}
	}

	// φ関数
	for (int i = 1; i < SIZE; i++) {
		for (int j = i + i; j < SIZE; j += i) {
			phi[j] -= phi[i];
		}
		phiSum.emplace_back(phiSum.back() + phi[i]);
	}

	// メビウス関数
	for (int i = 2; i < SIZE; i++) {
		if (!isPrime[i]) continue;
		mobius[i] = -1;
		for (int j = i + i; j < SIZE; j += i) {
			if ((j / i) % i == 0) mobius[j] = 0;
			else mobius[j] = -mobius[j];
		}
	}
}

// 高速ゼータ変換
void FastZeta(vector<ll>& X) {
	int N = X.size();
	if (isPrime.size() < N)
		Eratosthenes(N);

	for (auto p : prime) {
		if (p >= N) break;

		for (int i = (N - 1) / p; i >= 1; i--) {
			X[i] += X[i*p];
		}
	}
}

// 高速メビウス変換
void FastMobius(vector<ll>& X) {
	int N = X.size();
	if (isPrime.size() < N)
		Eratosthenes(N);
	
	for (auto p : prime) {
		if (p >= N) break;

		for (int i = 1; i * p <= N - 1; i++) {
			X[i] -= X[i * p];
		}
	}
}

int EulerPhi(int N) {
	int phi = N;
	for (int i = 2; i * i <= N; i++) {
		if (N % i) continue;
		phi = phi / i * (i - 1);
		while ((N % i) == 0) N /= i;
	}
	if (N > 1)
		phi = phi / N * (N - 1);
	return phi;
}
struct Solver
{
	void Run()
	{
		int N;
		cin >> N;
		cout << 1+phiSum[N] << "\n";
	}
};

int main()
{
	std::cin.tie(nullptr); //★インタラクティブ注意★
	std::ios_base::sync_with_stdio(false);
	int T = 1;
	Eratosthenes(1000010);

	cin >> T;
	while (T--)
	{
		Solver S;
		S.Run();
	}

	return 0;
}

/// 値渡しになっていないか?
/// 入力を全部読んでいるか? 途中でreturnしない
/// 32bitで収まるか? 10^5数えるとき
/// modは正しいか?
/// multisetでcountしていないか?
accuracy: 1
time_ms: 30
memory_kb: 23736
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll,ll>;
using vp = vector<pl>;
#define rep(i,n) for(ll i=0;i<(ll)(n);++i)
#define reps(i,s,n) for(ll i=(s);i<(ll)(n);++i)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);++i)
template<typename T>inline bool chmax(T &a,T b){return a<b?a=b,true:false;}
template<typename T>inline bool chmin(T &a,T b){return a>b?a=b,true:false;}
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define be(v) (v).begin(),(v).end()
const long long INF = 1e18;
#ifdef DEBUG
#include <debug.hpp>
#endif


// エラトステネスの篩
struct Eratosthenes {
	vector<bool> isprime;
	vector<ll> minfactor;
	Eratosthenes(ll N) : isprime(N+1, true),
							minfactor(N+1, -1) {
		isprime[1] = false;
		minfactor[1] = 1;
		for (ll p = 2; p <= N; ++p) {
			if (!isprime[p]) continue;
			minfactor[p] = p;
			for (ll q = p * 2; q <= N; q += p) {
				isprime[q] = false;
				if (minfactor[q] == -1) minfactor[q] = p;
			}
		}
	}
	vector<pair<ll,ll>> factorize(ll n) {
		vector<pair<ll,ll>> res;
		while (n > 1) {
			ll p = minfactor[n];
			ll exp = 0;
			while (minfactor[n] == p) {
				n /= p;
				++exp;
			}
			res.emplace_back(p, exp);
		}
		return res;
	}
	// 高速約数列挙
	vector<ll> divisors(ll n) {
		vector<ll> res({1});
		auto pf = factorize(n);
		for (auto p : pf) {
			ll s = (ll)res.size();
			for (ll i = 0; i < s; ++i) {
				ll v = 1;
				for (ll j = 0; j < p.second; ++j) {
					v *= p.first;
					res.push_back(res[i] * v);
				}
			}
		}
		return res;
	}
};
ll solve(){
	#ifdef DEBUG
	cout << "--- Input ---" << endl;
	#endif
	ll N=1000000;
	Eratosthenes er(N);
	vl euler(N+1);
	rep(n,N+1){
		vp p=er.factorize(n);
		euler.at(n)=n;
		for(auto e:p){
			euler.at(n) *= e.fi-1;
			euler.at(n) /= e.fi;
		}
	}
	vl sum(N+2);
	rep(n,N+1){
		sum.at(n)+=euler.at(n);
		sum.at(n+1)+=sum.at(n);
	}
	#ifdef DEBUG
	cout<<"N="<<N<<endl;
	rep(i,100){
		cout<<"i="<<i<<" "<<euler.at(i)<<" "<<sum.at(i)<<endl;
	}
	cout << "--- Logic ---" << endl;
	#endif
	ll Q;cin>>Q;
	rep(qi,Q){
		ll n; cin>>n;
		cout<<sum.at(n)+1<<endl;
	}
	#ifdef DEBUG
	cout << "--- Answer ---" << endl;
	#endif
	return true;
}
int main(){
	#ifdef DEBUG
	cout << "--- Main ---" << endl;
	#endif
	solve();
	//while(solve());
	return 0;
}
//cout << fixed << setprecision(9);
accuracy: 1
time_ms: 100
memory_kb: 26372
final_rank: 16

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include<sstream>
#include<list>
#include<iomanip>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <bitset>
#include <cassert>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
const int INF = 100000000;
const long long LINF = 3e18 + 7;
const int MAX_N = 1000010;
const int MAX_W = 10002;
const int MAX_ARRAYK = 100000;
double PI = 3.14159265358979323846;
//using ll = long long;


long long euler[MAX_N];
long long answer[MAX_N];
void euler_phi2() {
	for (long long i = 0; i < MAX_N; i++) {
		euler[i] = i;
	}
	for (long long i = 2; i < MAX_N; i++) {
		if (euler[i] == i) {
			for (long long j = i; j < MAX_N; j += i) {
				euler[j] = euler[j] / i * (i - 1);
			}
		}
	}
}

int main() {

	// Farey Sequence
	euler_phi2();
	answer[1] = 2;
	for (long long i = 2; i < MAX_N; i++) {
		answer[i] = answer[i - 1] + euler[i];
	}
	int T, M;
	cin >> T;
	for (int t = 0; t < T; t++) {
		cin >> M;
		cout << answer[M] << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 18740
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define mod 998244353
#define endl '\n'
#define AC ios_base::sync_with_stdio(false);cin.tie(0);
#define INF 10e17

int cnt[(int)10e6];

void del(int pos){
    for(int i=pos*2;i<=10e6;i+=pos){
        cnt[i]-=cnt[pos];
    }
}

signed main(){
    cnt[0]=0;
    rep1(i,(int)10e6)cnt[i]=i+1;
    rep1(i,(int)10e6)del(i);
    //累積和をとる
    rep1(i,(int)10e6)cnt[i]+=cnt[i-1];
    int t;
    cin>>t;
    rep(i,t){
        int n;
        cin>>n;
        cout<<cnt[n]<<endl;
    }

    
}
accuracy: 1
time_ms: 1700
memory_kb: 81136
final_rank: 20

code_snippet: #define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2286"

#include <bits/stdc++.h>

template <class T> struct CumulativeSum {
    std::vector<T> seg;
    int n;

    CumulativeSum(int n) : n(n), seg(n + 1, 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[p] = x
    void set(int p, T x) {
        assert(0 <= p and p < n);
        seg[p + 1] = x;
    }

    // A[p] += x
    void add(int p, T x) {
        assert(0 <= p and p < n);
        seg[p + 1] += x;
    }

    // A[l] += x, A[l + 1] += x, ... , A[r - 1] += x
    void imos(int l, int r, T x = T(1)) {
        add(l, x);
        add(r, -x);
    }

    void build() {
        for (int i = 0; i < n; i++) seg[i + 1] += seg[i];
    }

    T operator[](int p) const {
        assert(0 <= p and p < n);
        return seg[p + 1];
    }

    // output
    friend std::ostream &operator<<(std::ostream &os, const CumulativeSum &A) {
        for (int i = 0; i <= A.n; i++) os << A.seg[i] << " \n"[i == A.n];
        return os;
    }
};

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;
}

int main() {
    auto ttt = totient_table(1000000);
    std::vector<long long> tl(ttt.size());
    for (int i = 0; i < (int)ttt.size(); i++) tl[i] = ttt[i];
    CumulativeSum<long long> rui(tl);
    int tt;
    std::cin >> tt;
    while (tt--) {
        int n;
        std::cin >> n;
        std::cout << rui.sum(0, n + 1) + 1 << '\n';
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 22296
final_rank: 12

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include<sstream>
#include<list>
#include<iomanip>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <bitset>
#include <cassert>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
const int INF = 100000000;
const long long LINF = 3e18 + 7;
const int MAX_N = 1000010;
const int MAX_W = 10002;
const int MAX_ARRAYK = 100000;
double PI = 3.14159265358979323846;
//using ll = long long;


long long prime[MAX_N];
bool is_prime[MAX_N];

long long sieve(long long n) {
	long long p = 0;
	for (long long i = 0; i <= n; i++) {
		is_prime[i] = true;
	}
	is_prime[0] = is_prime[1] = false;
	for (long long i = 2; i <= n; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (long long j = 2 * i; j <= n; j += i) {
				is_prime[j] = false;
			}
		}
	}

	return p;
}

// https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2286
// https://ncastar.hatenablog.com/entry/20140320/1395323746
// https://qiita.com/hidekikangeki/items/e2524f199ae1d483f060
// 包除原理、オイラーのφ関数
// https://nanikaka.hatenadiary.org/entry/20111224/1324690802

long long euler[MAX_N];
long long answer[MAX_N];
void euler_phi2() {
	for (long long i = 0; i < MAX_N; i++) {
		euler[i] = i;
	}
	for (long long i = 2; i < MAX_N; i++) {
		if (euler[i] == i) {
			for (long long j = i; j < MAX_N; j += i) {
				euler[j] = euler[j] / i * (i - 1);
			}
		}
	}
}

int main() {

	//long long N = sieve(100);
	//cout << N << endl;
	//for (long long i = 0; i < N; i++) {
	//	cout << prime[i] << " ";
	//}
	//cout << endl;

	euler_phi2();
	answer[1] = 2;
	for (long long i = 2; i < MAX_N; i++) {
		answer[i] = answer[i - 1] + euler[i];
	}
	int T, M;
	cin >> T;
	for (int t = 0; t < T;t++) {
		cin >> M;
		cout << answer[M] << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 18600
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using i32 = int;

i32 main() {
	i32 size = 1000000;
	vector ps(size + 1, 0LL);
	for (i32 i = 0 ; i < size + 1 ; i++) {
		ps[i] = i;
	}
	for (i32 i = 1 ; i < size + 1 ; i++) {
		for (i32 j = i * 2 ; j < size + 1 ; j += i) {
			ps[j] -= ps[i];
		}
	}
	vector s = { 0LL };
	partial_sum(ps.begin(), ps.end(), back_inserter(s));
	i32 t; cin >> t;
	for (i32 _ = 0 ; _ < t ; _++) {
		i32 n; cin >> n;
		cout << s.at(n + 1) + 1 << endl;
	}
}
accuracy: 1
time_ms: 30
memory_kb: 18820
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using C = complex<double>;
const int mod = 998244353;
const long long LINF = 1001002003004005006;
const int INF = 1001001001;
const double PI = acos(-1);
const double EPS = 1e-10;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};
const int dx[8] = {1,1,1,0,0,-1,-1,-1};
const int dy[8] = {1,0,-1,1,-1,1,0,-1};
# define sz(x) (int)(x).size()
# define rsz(x,n) x.resize(n)
# define yosupo(x) {cout << (x) << endl; return 0;}
# define ll long long
# define fi first
# define se second
# define pb push_back
# define pf push_front
# define eb emplace_back
# define ef emplace_front
# define pob pop_back
# define pof pop_front
# define GET_MACRO(_1, _2, _3, NAME, ...) NAME
# define _rep(i, n) _rep2(i, 0, n)
# define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
# define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
# define srep(i, a, b) for(int i = a; i <= b; ++i)
# define all(obj) (obj).begin(), (obj).end()
# define rall(obj) (obj).rbegin(), (obj).rend()
inline void YesNo(bool f) { std::cout << (f? "Yes": "No") << std::endl; }
void read() {}
template <typename T, class... U> void read(T &t, U &...u) { cin >> t; read(u...); }
void writeln() { cout << endl; }
template <typename T, class... U, char sep = ' '> void writeln(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << sep; writeln(u...); }
# define Pll pair<ll, ll>
# define P pair<int,int>
# define bit(x,i) (((x) >> (i)) & 1)
# define equals(a, b) (fabs((a) - (b)) < EPS) // 誤差を考慮した同値判定
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << "P(" << p.first << " " << p.second << ")";}
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
using vi = vc<int>; using vvi = vv<int>;
using vl = vc<ll>; using vvl = vv<ll>;

#define MAX_N 1000100

ll euler[MAX_N], ans[MAX_N];

void euler_phi2() {
    rep(i,MAX_N) euler[i] = i;
    rep(i,2,MAX_N) {
        if(euler[i] == i) {
            for(int j = i; j < MAX_N; j+=i) euler[j] = euler[j]*(i-1)/i;
        }
    }
}

int main() {
    euler_phi2();
    int t;
    scanf("%d",&t);
    ans[1] = 2;
    rep(i,1,MAX_N-1) ans[i+1] = ans[i]+euler[i+1];
    rep(ti,t) {
        int n;
        scanf("%d",&n);
        cout << ans[n] << endl;
    }
}
accuracy: 1
time_ms: 20
memory_kb: 18832
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using C = complex<double>;
const int mod = 998244353;
const long long LINF = 1001002003004005006;
const int INF = 1001001001;
const double PI = acos(-1);
const double EPS = 1e-10;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};
const int dx[8] = {1,1,1,0,0,-1,-1,-1};
const int dy[8] = {1,0,-1,1,-1,1,0,-1};
# define sz(x) (int)(x).size()
# define rsz(x,n) x.resize(n)
# define yosupo(x) {cout << (x) << endl; return 0;}
# define ll long long
# define fi first
# define se second
# define pb push_back
# define pf push_front
# define eb emplace_back
# define ef emplace_front
# define pob pop_back
# define pof pop_front
# define GET_MACRO(_1, _2, _3, NAME, ...) NAME
# define _rep(i, n) _rep2(i, 0, n)
# define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
# define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
# define srep(i, a, b) for(int i = a; i <= b; ++i)
# define all(obj) (obj).begin(), (obj).end()
# define rall(obj) (obj).rbegin(), (obj).rend()
inline void YesNo(bool f) { std::cout << (f? "Yes": "No") << std::endl; }
void read() {}
template <typename T, class... U> void read(T &t, U &...u) { cin >> t; read(u...); }
void writeln() { cout << endl; }
template <typename T, class... U, char sep = ' '> void writeln(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << sep; writeln(u...); }
# define Pll pair<ll, ll>
# define P pair<int,int>
# define bit(x,i) (((x) >> (i)) & 1)
# define equals(a, b) (fabs((a) - (b)) < EPS) // 誤差を考慮した同値判定
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << "P(" << p.first << " " << p.second << ")";}
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
using vi = vc<int>; using vvi = vv<int>;
using vl = vc<ll>; using vvl = vv<ll>;

#define MAX_N 1000100

ll euler[MAX_N], ans[MAX_N];

void euler_Phi() {
    rep(i,MAX_N) euler[i] = i;
    rep(i,2,MAX_N) {
        if(euler[i] == i) {
            for(int j = i; j < MAX_N; j+=i) euler[j] = euler[j]*(i-1)/i;
        }
    }
}

int main() {
    euler_Phi();
    int t;
    scanf("%d",&t);
    ans[1] = 2;
    rep(i,1,MAX_N-1) ans[i+1] = ans[i]+euler[i+1];
    rep(ti,t) {
        int n;
        scanf("%d",&n);
        cout << ans[n] << endl;
    }
}
accuracy: 1
time_ms: 20
memory_kb: 18888
final_rank: 5

code_snippet: // 2021.12.2
// #define _GLIBCXX_DEBUG
// #define __USE_MATH_DEFINES // const double PI = acos(-1.0)
#include <bits/stdc++.h>
using namespace std;
// (*) snipet
// type name
using ll = long long;
using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>;
using vpii = vector<pii>; using vpil = vector<pil>; using vpli = vector<pli>; using vpll = vector<pll>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
template <typename T> using pq = priority_queue<T, vector<T>>;
template <typename T> using pql = priority_queue<T, vector<T>, greater<T>>;
// rep
#define rep0(goal) for (int cnt = 0; cnt < int(goal); ++cnt)
#define rep(cnt, goal) for (int cnt = 0; cnt < int(goal); ++cnt)
#define rep2(cnt, start, goal) for (int cnt = int(start); cnt < int(goal); ++cnt)
#define rep3(cnt, start, goal) for (int cnt = int(start); cnt > int(goal); --cnt)
// all
#define all(ctn) begin(ctn), end(ctn)
// chmax, chmin
template <typename T> bool chmax(T &x, const T y) { if (x < y) { x = y; return true; } else { return false; }}
template <typename T> bool chmin(T &x, const T y) { if (x > y) { x = y; return true; } else { return false; }}
// etc.
void Yn(const bool &exp) { if (exp) cout << "Yes" << endl; else cout << "No" << endl;}
void set_prec(const int &dig) { cout << fixed << setprecision(dig); cerr << fixed << setprecision(dig);}
// template <typename T> T INF() { return numeric_limits<T>::max();}
// template <typename T> T MIN_INF() { return numeric_limits<T>::min();}

// #include <atcoder/all>
// using namespace atcoder;
// using mint = atcoder::modint1000000007;
// using mint = atcoder::modint998244353;
// // using mint = atcoder::modint;
// void pr(const mint &MINT) { cerr << MINT.val(); } // mint
// using pmm = pair<mint, mint>; using pim = pair<int, mint>; using pmi = pair<mint, int>; using plm = pair<ll, mint>; using pml = pair<mint, ll>;
// using vm = vector<mint>; using vvm = vector<vm>; using vvvm = vector<vvm>;

// debug
template <typename T> void pr(const T &obj) { cerr << obj; } // single
template <typename T, typename ...Ts> void pr(const T &first, const Ts &...rest) { pr(first); cerr << ", "; pr(rest...); } // multi(plural)
template <typename S, typename T> void pr(const pair<S, T> &PAIR) { cerr << "("; pr(PAIR.first); cerr << ", "; pr(PAIR.second); cerr << ")"; } // pair
template <typename S, typename T, typename U> void pr(const tuple<S, T, U> &trp) { cerr << "("; pr(get<0>(trp)); cerr << ", "; pr(get<1>(trp)); cerr << ", "; pr(get<2>(trp)); cerr << ")"; } // tuple(3)
template <typename T> void pr(const vector<T> &vec) { cerr << "{"; for (T obj : vec) { pr(obj); cerr << ", "; } cerr << "}"; } // vector
template <typename T> void pr(const vector<vector<T>> &vv) { rep(row, vv.size()) { cerr << endl; cerr << "[" << row << "]: "; pr(vv[row]); }} // vector(multi-D)
template <typename T> void pr(const set<T> &SET) { cerr << "{"; for (T obj : SET) { pr(obj); cerr << ", "; } cerr << "}"; } // set
template <typename T> void pr(const multiset<T> &MS) { cerr << "{"; for (T obj : MS) { pr(obj); cerr << ", "; } cerr << "}"; } // multiset
template <typename S, typename T> void pr(const map<S, T> &MAP) { cerr << "{"; for (pair<S, T> p : MAP) { pr(p.first); cerr << ": "; pr(p.second); cerr << ", "; } cerr << "}";} // map
template <typename T> void pr(const queue<T> &que) { queue<T> q = que; cerr << "{"; while (!q.empty()) { pr(q.front()); q.pop(); cerr << ", ";} cerr << "}";} // queue
template <typename T> void pr(const deque<T> &deq) { deque<T> d = deq; cerr << "{"; while (!d.empty()) { pr(d.front()); d.pop_front(); cerr << ", ";} cerr << "}";} // deque
template <typename T> void pr(const stack<T> &stc) { stack<T> s = stc; vector<T> v; while (!s.empty()) { v.push_back(s.top()); s.pop();} reverse(all(v)); cerr << "{"; for (T obj : v) cerr << obj << ", "; cerr << "}";} // stack
template <typename T> void pr(const priority_queue<T> &pq) { priority_queue<T> p = pq; cerr << "{"; while (!p.empty()) { pr(p.top()); p.pop(); cerr << ", "; } cerr << "}";} // priority_queue
template <typename T> void pr(const priority_queue<T, vector<T>, greater<T>> &pq) { priority_queue<T, vector<T>, greater<T>> p = pq; cerr << "{"; while (!p.empty()) { pr(p.top()); p.pop(); cerr << ", ";} cerr << "}";} // priority_queue(from less)

#define db(obj) cerr << #obj << ": "; pr(obj); cerr << " ";
#define dl(obj) db(obj); cerr << endl;
#define dm(...) cerr << "(" << #__VA_ARGS__ << "): ("; pr(__VA_ARGS__); cerr << ") ";
#define dml(...) dm(__VA_ARGS__); cerr << endl;


// global
int t;
vi n;

vl a, b;
const int MAX_n = 1000000;

void input() {
	cin >> t;
	n = vi(t);
	rep(i, t) cin >> n[i];
}

void init() {
	input();
	a = vl(MAX_n + 1);
	b = vl(MAX_n + 2);
}

vector<pair<ll, int>> prime_factorization(ll N) {
	assert(1 <= N);
	vector<pair<ll, int>> res;
	for (ll p = 2; p * p <= N; ++ p) if (N % p == 0) {
		int d = 0;
		for (; N % p == 0; N /= p) ++d;
		res.push_back(make_pair(p, d));
	}
	if (N > 1) res.push_back(make_pair(N, 1));
	return res;
}

// オイラーのφ関数
ll phi(ll N) {
	for (auto &[p, d] : prime_factorization(N)) N = N / p * (p - 1);
	return N;
}

ll sub_solve(ll N) {
	ll res = 1;
	rep2(k, 1, N + 1) res += phi(k);
	return res;
}

void solve() {
	a[0] = 1;
	rep2(N, 1, MAX_n + 1) a[N] = phi(N);
	rep(N, MAX_n + 1) b[N + 1] = b[N] + a[N];
	// dl(a); dl(b); //
	rep(i, t) cout << b[n[i] + 1] << endl;
}

void test() {
}

int main() {
	init();
	// test(); //
	solve();
}
accuracy: 1
time_ms: 1180
memory_kb: 18668
final_rank: 17

code_snippet: #include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <string>
#include <bitset>
#include <assert.h>
#include <functional>

// #define _GLIBCXX_DEBUG
// #define _LIBCPP_DEBUG 0
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define revrep(i, n) for(int i = (int)(n - 1); i >= 0; --i)
#define range(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrange(i, s, t) for(int i = (int)(t - 1); i >= (int)(s); --i)
#define srange(i, s, t, step) for(int i = (int)(s); i < (int)(t); i += (int)(step))
#define popcnt(x) __builtin_popcountll(x)
#define hayai std::ios::sync_with_stdio(false);std::cin.tie(nullptr)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }
inline bool inside(int x, int y, int h, int w) { return (x >= 0 && x < h && y >= 0 && y < w); }
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};



//https://qiita.com/drken/items/3beb679e54266f20ab63
struct Erastothenes {
    vector<bool> is_prime;    
    vector<int> min_factor;    
    vector<int> moebius;    
    Erastothenes(int n): is_prime(n + 1, true),
                         min_factor(n + 1, -1),
                         moebius(n + 1, 1) {
        is_prime[1] = false;
        min_factor[1] = 1;

        for(int p = 2; p <= n; ++p) {
            if (!is_prime[p]) continue;
            min_factor[p] = p;
            moebius[p] = -1;
            for(int q = p + p; q <= n; q += p) {
                is_prime[q] = false;
                if (min_factor[q] == -1) min_factor[q] = p;
                if ((q / p) % p == 0) moebius[q] = 0;
                else moebius[q] = -moebius[q];
            }
        }
    }
};


const int NMAX = 1e6+1;
ll farey_size[NMAX];

void pre_calc() {
    Erastothenes sieve(NMAX);
    range(i, 1, NMAX) {
        srange(j, i, NMAX, i) {
            farey_size[j] += sieve.moebius[i] * (j / i);
        }
    }
    farey_size[1] = 2;
    range(i, 2, NMAX) farey_size[i] += farey_size[i-1];
}


int main() {
    hayai; pre_calc();
    int n;
    cin >> n;
    rep(i, n) {
        int k;
        cin >> k;
        cout << farey_size[k] << "\n";
    }
}
accuracy: 1
time_ms: 50
memory_kb: 18572
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll Euler_Phi_Function(ll v){
    ll ans=v,v2=v;
    if(v2%2==0){ans-=ans/2;while(v2%2==0)v2/=2;}
    if(v2%3==0){ans-=ans/3;while(v2%3==0)v2/=3;}
    for(ll i=5;i*i<=v2;i+=4){
        if(v2%i==0){ans-=ans/i;while(v2%i==0)v2/=i;}
        i+=2;
        if(v2%i==0){ans-=ans/i;while(v2%i==0)v2/=i;}
    }
    if(v2!=1)ans-=ans/v2;
    return ans;
}

int main(){
    vector<ll> tb(1000001);
    tb[1] = 2;
    for(int i = 2; i <= 1000000; i++){
        tb[i] = tb[i - 1] + Euler_Phi_Function(i);
    }
    int T, v;
    cin >> T;
    while(T--){
        cin >> v;
        cout << tb[v] << '\n';
    }
}
accuracy: 1
time_ms: 390
memory_kb: 10544
final_rank: 14

code_snippet: #include <bits/stdc++.h>
// clang-format off
#define rep(i, s ,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using ll = long long;
// 2^60
#define INF (1LL << 60)
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
using Graph = vector<vector<int>>;
template <typename T> ostream &operator<<(ostream &s, vector<vector<vector<T>>> const &v) { for (int i = 0; i < int(v.size()); ++i) { s << "[" << i << "]" << endl; s << v[i];} return s;}
template <typename T> ostream &operator<<(ostream &s, vector<vector<T>> const &v) { for (int i = 0; i < int(v.size()); ++i ){ s << v[i];} return s;}
template <typename T> ostream &operator<<(ostream &s, vector<T> const &v) { for (int i = 0; i < int(v.size()); ++i) { s << v[i]; if (i != int(v.size()) - 1) { s << ",";}} s << endl; return s;}
// clang-format on

// 幅優先の例
// 入力: グラフ G と，探索の始点 s
// 出力: s から各頂点への最短路長を表す配列
vector<int> BFS(const Graph &G, int s)
{
    int N = (int)G.size(); // 頂点数
    // vector<bool> seen(N, false);
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    dist[s] = 0;
    que.push(s);

    while (!que.empty())
    {
        int v = que.front();
        que.pop();

        for (int x : G[v])
        {
            if (dist[x] != -1)
                continue;

            dist[x] = dist[v] + 1;
            que.push(x);
        }
    }
    return dist;
}

// エラトステネスの篩
struct Eratosthenes
{
    // テーブル
    vector<bool> isprime;

    // 整数 i を割り切る最小の素数
    vector<int> minfactor;

    // メビウス関数値
    // * μ(1)=1
    // * nがある素数pで2回以上割り切れるとき、μ(n)=0
    // * n=p1×p2×…pkと素因数分解できるとき、μ(n)=(−1)^K
    vector<int> mobius;

    // コンストラクタで篩を回す
    Eratosthenes(int N) : isprime(N + 1, true),
                          minfactor(N + 1, -1),
                          mobius(N + 1, 1)
    {
        // 1 は予めふるい落としておく
        isprime[1] = false;
        minfactor[1] = 1;

        // 篩
        for (int p = 2; p <= N; ++p)
        {
            // すでに合成数であるものはスキップする
            if (!isprime[p])
                continue;

            // p についての情報更新
            minfactor[p] = p;
            mobius[p] = -1;

            // p 以外の p の倍数から素数ラベルを剥奪
            for (int q = p * 2; q <= N; q += p)
            {
                // q は合成数なのでふるい落とす
                isprime[q] = false;

                // q は p で割り切れる旨を更新
                if (minfactor[q] == -1)
                    minfactor[q] = p;
                // update mobius
                if ((q / p) % p == 0)
                    mobius[q] = 0;
                else
                    mobius[q] = -mobius[q];
            }
        }
    }

    // 高速素因数分解
    // pair (素因子, 指数) の vector を返す
    vector<pair<int, int>> factorize(int n)
    {
        vector<pair<int, int>> res;
        while (n > 1)
        {
            int p = minfactor[n];
            int exp = 0;

            // n で割り切れる限り割る
            while (minfactor[n] == p)
            {
                n /= p;
                ++exp;
            }
            res.emplace_back(p, exp);
        }
        return res;
    }

    // 高速約数列挙
    // 計算量はnの約数の個数をσ(n)として、O(σ(n))となります。n≤10^9の範囲では、σ(n)≤1344(n=735134400で最大)
    vector<int> divisors(int n)
    {
        vector<int> res({1});

        // n を素因数分解 (メンバ関数使用)
        auto pf = factorize(n);

        // 約数列挙
        for (auto p : pf)
        {
            int s = (int)res.size();
            for (int i = 0; i < s; ++i)
            {
                int v = 1;
                for (int j = 0; j < p.second; ++j)
                {
                    v *= p.first;
                    res.push_back(res[i] * v);
                }
            }
        }
        return res;
    }
};

int main()
{
    cout << fixed << setprecision(16);
    int t;
    cin >> t;

    int MAXN = 1e6;
    vector<ll> sum(MAXN + 1);
    sum[1] = 2;
    Eratosthenes er(MAXN);

    rep(x, 2, MAXN + 1)
    {
        // i以下の互いに素な個数
        ll cnt = x;
        for (auto [p, r] : er.factorize(x))
        {
            cnt = cnt / p * (p - 1);
        }
        sum[x] = sum[x - 1] + cnt;
    }

    rep(i, 0, t)
    {
        int n;
        cin >> n;
        cout << sum[n] << endl;
    }
}
accuracy: 1
time_ms: 90
memory_kb: 18804
final_rank: 11

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <map>
#include <queue>

using namespace std;

using ll = long long;
using pii = pair<int, int>;	using pll = pair<ll, ll>;	using pil = pair<int, ll>;	using pli = pair<ll, int>;
using vi = vector<int>;		using vvi = vector<vi>;		using vvvi = vector<vvi>;
using vll = vector<ll>;		using vvll = vector<vll>;	using vvvll = vector<vvll>;
using vb = vector<bool>;	using vvb = vector<vb>;		using vvvb = vector<vvb>;
template <class T> using pqr = priority_queue<T, vector<T>, greater<T>>;

const ll INFL = (ll)1e18;	const int INF = (int)1e9;
const int MOD = 1000000007;

template <class T> inline bool chmax(T& M, const T& x) { if (M < x) { M = x; return true; } return false; } // 最大値を更新（更新されたら true を返す）
template <class T> inline bool chmin(T& m, const T& x) { if (m > x) { m = x; return true; } return false; } // 最小値を更新（更新されたら true を返す）


//ユークリッドの互除法
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//拡張ユークリッドの互除法
ll extgcd(ll a, ll b, ll& x, ll& y) {
	ll d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1; y = 0;
	}
	return d;
}

//素数判定O(\sqrt(n))
bool is_prime(int n) {
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)
			return false;
	}
	return n != 1;
}

//エラトステネスの篩
int sieve(int n, vi& prime, vb& is_prime) {
	int p = 0;
	for (int i = 0; i <= n; i++)
		is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j <= n; j += i)
				is_prime[j] = false;
		}
	}
	return p;
}

int main()
{
	const int MAX_NUM = 1000000;
	int t;
	cin >> t;


	//素数とオイラー関数の計算
	vi prime(MAX_NUM + 1);
	vb is_prime(MAX_NUM + 1);
	vi euler(MAX_NUM + 1, 1);
	int p = 0;
	//初期化
	for (int i = 0; i <= MAX_NUM; i++)
		is_prime[i] = true;

	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= MAX_NUM; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			euler[i] = i - 1;
			for (int j = 2 * i; j <= MAX_NUM; j += i) {
				is_prime[j] = false;
				int tmp = j, pow = 1;
				//素因数のべきを求める
				while (tmp % i == 0) {
					tmp /= i;
					pow *= i;
				}
				//オイラー関数の計算
				euler[j] *= pow - pow / i;

			}
		}
	}


	//数列計算
	vll F(MAX_NUM + 1);
	F[1] = 2;
	for (int i = 2; i <= MAX_NUM; i++) {
		F[i] = F[i - 1] + euler[i];
	}

	vll ans;
	for (int i = 0; i < t; i++) {
		int n;
		cin >> n;
		ans.push_back(F[n]);
	}


	for (auto a : ans)
		cout << a << endl;

	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 19064
final_rank: 6