1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 using namespace std; 5 typedef long long ll; 6 ll x, ans=0; 7 int euler[10000005]; 8 void e(int n){ 9 euler[1]=1; 10 for(int i=2; i<=n; i++) euler[i]=i; 11 for(int i=2; i<=n; i++) 12 if(euler[i]==i) 13 for(int j=i; j<n; j+=i) 14 euler[j]=euler[j]/i*(i-1); 15 } 16 int main(){ 17 //freopen("coin.in","r",stdin); 18 //freopen("coin.out","w",stdout); 19 cin>>x; 20 ll up=sqrt(x); 21 e(up+1); 22 for(ll i=1; i<=up; i++){ 23 ans+=euler[i]*floor(x/(i*i)); 24 } 25 cout<<ans; 26 //fclose(stdin); 27 //fclose(stdout); 28 return 0; 29 }
原文:https://www.cnblogs.com/Aze-qwq/p/9409536.html