莫比乌斯反演。
是NOI2010能量采集的翻版
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef int INT;
#define ll long long
#define int ll
ll phi(ll x){
ll ret=x;
for(int i=2;i*i<=x;i++){
if(x%i==0){
ret=ret*(i-1)/i;
}
while(x%i==0){
x/=i;
}
}
// cout<<x<<" "<<ret<<endl;
if(x>1){
ret=ret*(x-1)/x;
}
return ret;
}
INT main(){
ll n;
// cout<<phi(7)<<endl;
scanf("%lld",&n);
ll ans=0;
for(int i=1;i*i<=n;i++){
if(n%i==0){
ans+=i*(phi(n/i));
if((n/i)!=i){
ans+=(n/i)*phi(i);
}
}
}
cout<<ans<<endl;
}