题意很简洁不说了
题解:一开始我想直接暴力,复杂度是O(log(1e7)*sqrt(1e7))算出来是2e9,可能会复杂度爆炸,但是我看时限是10s,直接大力莽了一发暴力,没想到就过了= =
就是先打出1e7的素数表,然后挨个算即可
//#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define C 0.5772156649 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #define pil pair<int,ll> #define pii pair<int,int> #define ull unsigned long long #define base 1000000000000000000 #define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-12; const int N=10000000+10,maxn=400000+10,inf=0x3f3f3f3f; int mu[N],prime[N],sum[N]; bool mark[N]; int cnt; void init() { mu[1]=1; cnt=0; for(int i=2;i<N;i++) { if(!mark[i])prime[++cnt]=i,mu[i]=-1; for(int j=1;j<=cnt;j++) { int t=i*prime[j]; if(t>N)break; mark[t]=1; if(i%prime[j]==0){mu[t]=0;break;} else mu[t]=-mu[i]; } } for(int i=1;i<N;i++)sum[i]=sum[i-1]+mu[i]; } int main() { init(); int n; scanf("%d",&n); ll ans=0; for(int i=1;i<=cnt;i++) { int te=n/prime[i]; for(int j=1,last;j<=te;j=last+1) { last=te/(te/j); ans+=(ll)(sum[last]-sum[j-1])*(te/j)*(te/j); } } printf("%lld\n",ans); return 0; } /******************** ********************/