数论分块的板子题,主要精华就一点:
剩下的可以看数论分块 - OI Wiki (oi-wiki.org)
#include "bits/stdc++.h" using namespace std; typedef long long LL; LL t,n; inline LL h(LL x){ LL i,j,l,r,ans=0; for (l=1;l<=x;l=r+1){ r=(n/(n/l)); ans+=(n/l)*(r-l+1); } return ans; } int main(){ LL i,j,l,r; scanf("%lld",&t); while (t--){ scanf("%lld",&n); printf("%lld\n",h(n)); } return 0; }