3
Test instructions: give n positive integers to find out how many of these n numbers are in the number of interconnects.
Analysis:
Fr=aladdin "> The inverse of the mo.
f (d) " Span style= "Font-family:tahoma" >n number of GCD d f (d) n GCD happens to be d
the F (d) =∑f (n) (n d = = 0)
F (d) =∑mu[n/d] * f (n) (n%d = = 0)
The above two formulas are the formulas in Möbius inversion.
So there's a number of pairs that require a mutual-vegetarian. is to ask f (1).
And according to the above formula can be obtained f (1) =∑mu[n] * f (n).
So get mu[] and enumerate n . Mu[i] is the Möbius function of I.
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int maxn = 1e5 + 10; typedef long Long Ll;int CNT[MAXN], PRI[MAXN], NUM[MAXN], Pri_num, MU[MAXN], VIS[MAXN], a[maxn];void Mobius (int n)//sieve method to find Mo Biousse function {pri_num = 0; memset (Vis, 0, sizeof (VIS)); VIS[1] = mu[1] = 1; for (int i = 2; I <= n; i++) {if (!vis[i]) {pri[pri_num++] = i; Mu[i] =-1; } for (int j = 0; J < Pri_num; J + +) {if (i * pri[j] > N) break; VIS[I*PRI[J]] = 1; if (i% pri[j] = = 0) {Mu[i*pri[j]] = 0; Break } Mu[i*pri[j]] =-mu[i]; }}}ll get (int x) {return (LL) x * (x-1)/2;} int main () {Mobius (100005); int n; while (~SCANF ("%d", &n)) {int Mmax = 0; for (int i = 1; I <= n; i++) {scanf ("%d", &a[i]); Mmax = Max (Mmax, A[i]); } memset (CNT, 0, sizeof (CNT)); MEmset (num, 0, sizeof (num)); for (int i = 1; I <= n; i++) num[a[i]]++; for (int i = 1, i <= Mmax; i++) for (int j = i; J <= Mmax; j + = i) cnt[i] + = num[j]; LL ans = 0; for (int i = 1; I <= Mmax; i++) ans + = Get (Cnt[i]) * Mu[i]; printf ("%lld\n", ans); } return 0;}