SP3871 GCDEX - GCD Extreme

时间:2023-12-04 19:37:02
//author Eterna
#define Hello the_cruel_world!
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<cmath>
#include<climits>
#include<deque>
#include<functional>
#include<complex>
#include<numeric>
#include<unordered_map>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define Pi acos(-1.0)
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))
#define pb(x) push_back(x)
#define lowbit(x) (x & -x)
#define FRIN freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\in.txt", "r", stdin)
#define FROUT freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\out.txt", "w", stdout)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define outd(x) printf("%d\n", x)
#define outld(x) printf("%lld\n", x)
#define il inline
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 1e6;
const int INF = 0x7fffffff;
const int mod = 1e9 + ;
const double eps = 1e-;
inline int read_int() {
char c;
int ret = , sgn = ;
do { c = getchar(); } while ((c < '' || c > '') && c != '-');
if (c == '-') sgn = -; else ret = c - '';
while ((c = getchar()) >= '' && c <= '') ret = ret * + (c - '');
return sgn * ret;
}
inline ll read_ll() {
char c;
ll ret = , sgn = ;
do { c = getchar(); } while ((c < '' || c > '') && c != '-');
if (c == '-') sgn = -; else ret = c - '';
while ((c = getchar()) >= '' && c <= '') ret = ret * + (c - '');
return sgn * ret;
}
int phi[maxn + ], prime[maxn + ];
ll sum[maxn + ];
bool is_prime[maxn + ];
void init(int n, int cnt = ) {
for (int i = ; i <= n; ++i)is_prime[i] = true;
for (int i = ; i <= n; ++i) {
if (is_prime[i])prime[++cnt] = i, phi[i] = i - ;
for (int j = ; j <= cnt && i * prime[j] <= n; ++j) {
is_prime[i * prime[j]] = false;
if (i % prime[j])phi[i * prime[j]] = phi[i] * phi[prime[j]];
else {
phi[i * prime[j]] = phi[i] * prime[j];
break;
}
}
}
for (int i = ; i <= n; ++i)for (int j = ; j * i <= n; ++j)sum[i * j] += i * phi[j];
for (int i = ; i <= n; ++i)sum[i] += sum[i - ];
}
int n;
int main()
{
init(maxn);
while (n = read_int())printf("%lld\n", sum[n]);
//system("pause");
return ;
}