#include<bits/stdc++.h>
using namespace std;
#define fst first
#define sec second
#define sci(num) scanf("%d",&num)
#define scl(num) scanf("%lld",&num)
#define mem(a,b) memset(a,b,sizeof a)
#define cpy(a,b) memcopy(a,b,sizeof b)
typedef long long LL;
typedef pair<int,int> P;
const int MAX_N = 4e6 + 100;
const int MAX_M = 1e5 + 100;
int phi[MAX_N];
LL f[MAX_N];
void init() {
mem(f,0);
for (int i = 1;i < MAX_N;i++) phi[i] = i;
for (int i = 2;i < MAX_N;i++) {
if (phi[i] == i) {
for (int j = i;j < MAX_N;j+=i) {
phi[j] = phi[j] / i * (i - 1);
}
}
for (int j = 1;j *i < MAX_N;j++) {
f[i * j]+= phi[i] * j;
}
}
for (int i = 2;i <MAX_N;i++)
f[i] += f[i - 1];
}
int main() {
int N;
init();
while (~sci(N)) {
if (N == 0) break;
printf("%lld\n",f[N]);
}
return 0;
}
GCD - Extreme (II) UVA - 11426
最新推荐文章于 2023-01-26 22:23:01 发布