正解:欧拉函数
解题报告:
传送门$QwQ$
首先显然十分套路地变下形是趴
$\begin{align*}&=\sum_{i=1}^n\sum_{j=1}^n gcd(i,j)\\&=\sum_{i=1}^n\sum_{j=1}^n\sum_{d=1}^{min(i,j)} [gcd(i,j)==d]\cdot d\\&=\sum_{d=1}^{n}d\cdot \sum_{i=1}^n\sum_{j=1}^n [gcd(i,j)==d]\\\end{align*}$
然后就欧拉函数做呗?直接戳我简要总结里常见套路第一条,就能$O(n)$做了$QwQ$
(说下昂,这题里其实是无序的,所以最后用$phi$的时候就可以直接$i\cdot \phi(i)$鸭$QwQ$
其实本来还有一种方法的但因为某不便透露的原因被删了$kk$
#includeusing namespace std; #define il inline #define fi first #define sc second #define gc getchar() #define mp make_pair #define int long long #define P pair #define ri register int #define rc register char #define rb register bool #define rp(i,x,y) for(ri i=x;i<=y;++i) #define my(i,x,y) for(ri i=x;i>=y;--i) #define e(i,x) for(ri i=head[x];i;i=edge[i].nxt) const int N=2000000+10; int n,phi[N],sum[N],pr[N],pr_cnt,as; bool is_pr[N]; il int read() { rc ch=gc;ri x=0;rb y=1; while(ch!='-' && (ch>'9' || ch<'0'))ch=gc; if(ch=='-')ch=gc,y=0; while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc; return y?x:-x; } il void pre() { phi[1]=1; rp(i,2,N-10) { if(!is_pr[i])pr[++pr_cnt]=i,phi[i]=i-1;;sum[i]=sum[i-1]+phi[i]; rp(j,1,pr_cnt) { if(pr[j]*i>N-10)break;;is_pr[pr[j]*i]=1; if(!(i%pr[j])){phi[i*pr[j]]=phi[i]*pr[j];break;} phi[i*pr[j]]=phi[i]*phi[pr[j]]; } } } signed main() { //freopen("1390.in","r",stdin);freopen("1390.out","w",stdout); pre();n=read();rp(i,1,n/2)as+=i*sum[n/i]; printf("%lld\n",as); return 0; }