# 约数相关：约数个数()-其他

## 约数相关：约数个数()

N=(p1c1)*(p2c2)…(pk^ck)
N2=(p1(c1**2)) * (p2^ (c22) )…(pk^ (ck2) )

### 拍打牛头https://www.acwing.com/problem/content/1293/

``````#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1000010;

int n;
int a[N], cnt[N], s[N];

int main()
{
scanf("%d", &n);

for (int i = 0; i < n; i ++ )
{
scanf("%d", &a[i]);
cnt[a[i]] ++ ;//计数
}

for (int i = 1; i < N; i ++ )
for (int j = i; j < N; j += i)//倍数都加一遍 包括自己
s[j] += cnt[i];

for (int i = 0; i < n; i ++ ) printf("%d\n", s[a[i]] - 1);

return 0;
}

``````
————————

N=(p1c1)*(p2c2)…(pk^ck)
N2=(p1(c1**2)) * (p2^ (c22) )…(pk^ (ck2) )

### 拍打牛头https://www.acwing.com/problem/content/1293/

``````#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1000010;

int n;
int a[N], cnt[N], s[N];

int main()
{
scanf("%d", &n);

for (int i = 0; i < n; i ++ )
{
scanf("%d", &a[i]);
cnt[a[i]] ++ ;//计数
}

for (int i = 1; i < N; i ++ )
for (int j = i; j < N; j += i)//倍数都加一遍 包括自己
s[j] += cnt[i];

for (int i = 0; i < n; i ++ ) printf("%d\n", s[a[i]] - 1);

return 0;
}

``````