[SDOI2008]仪仗队

#include <iostream>

using namespace std;

const int N = 40010;

int primes[N], phi[N], cnt;
int n;
bool st[N];

int get_eulers(int n)
{
    phi[1] = 1;//特判一下 比如(1, 0)点,0也算和1互质,所以(1,0)点也能直接看到
    for(int i = 2; i <= n; i ++)
    {
        if(!st[i])
        {
            primes[cnt ++] = i;
            phi[i] = i - 1;
        }
        for(int j = 0; primes[j] <= n / i; j ++)
        {
            st[primes[j] * i] = true;
            if(i % primes[j] == 0)
            {
                phi[i * primes[j]] = phi[i] * primes[j];
                break;
            }
            phi[i * primes[j]] = phi[i] * (primes[j] - 1);
            //phi[i * p] = phi[i] * p          i % p = 0时成立
            //             phi[i] * (p - 1)    i % p != 0时成立
        }
    }
    
    int res = 0;
    for(int i = 1; i <= n; i ++) res += phi[i];
    return res;
}

int main()
{
    cin >> n;
    int res = get_eulers(n - 1);
    res = res * 2 + 1;
    cout << res;
    
    return 0;
}