洛谷 P2714 四元组统计
错误记录:42行N写成n;事实上除了读入以外,此题的小n没有任何用途
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<vector> 5 using namespace std; 6 #define fi first 7 #define se second 8 #define mp make_pair 9 #define pb push_back 10 typedef long long ll; 11 typedef unsigned long long ull; 12 typedef pair<int,int> pii; 13 const ll N=10000; 14 ll b[10100],ans; 15 ll mu[10100],prime[10100],len,n; 16 bool nprime[10100]; 17 ll F(ll x) 18 { 19 ll i,ans=0; 20 for(i=x;i<=N;i+=x) ans+=b[i]; 21 return __int128(ans)*(ans-1)*(ans-2)*(ans-3)/24; 22 } 23 int main() 24 { 25 ll i,j,t; 26 mu[1]=1; 27 for(i=2;i<=N;i++) 28 { 29 if(!nprime[i]) prime[++len]=i,mu[i]=-1; 30 for(j=1;j<=len&&i*prime[j]<=N;j++) 31 { 32 nprime[i*prime[j]]=1; 33 if(i%prime[j]==0) {mu[i*prime[j]]=0;break;} 34 else mu[i*prime[j]]=-mu[i]; 35 } 36 } 37 while(scanf("%lld",&n)==1) 38 { 39 memset(b,0,sizeof(b)); 40 for(i=1;i<=n;i++) scanf("%lld",&t),b[t]++; 41 ans=0; 42 for(i=1;i<=N;i++) 43 { 44 ans+=mu[i]*F(i); 45 } 46 printf("%lld\n",ans); 47 } 48 return 0; 49 }