define _CRT_SECURE_NO_WARNI NGS include cstdio include iostream includ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long
using namespace std;
int ans[2000001] = { 0 };
int q[2000001] = { 0 };
int prime[12] = {0};
int alfa[12] = {0};
void fill_prime(int k, int& ind)
{
for (int i = 2; (long long)i * i <= k; i++)
if (k % i == 0)
{
prime[ind] = i;
while (k % i == 0)
{
k /= i;
alfa[ind]++;
}
ind++;
}
if (k != 1)
{
prime[ind] = k;
alfa[ind]++;
ind++;
}
}
void find_mult(int ind)
{
vector<long long> m;
m.reserve(2000000);
m.push_back(1ll);
int sz = 1;
long long mult = 1;
long long temp = 0;
for (int i = 0; i < ind; i++)
{
sz = m.size();
mult = 1;
for (int j = 0; j < alfa[i]; j++)
{
mult *= prime[i];
for (int h = 0; h < sz; h++)
{
m.push_back(m[h] * mult);
}
}
}
for (int i = 0; i < m.size(); i++)
ans[m[i]]++;
}
int main() {
//freopen("input.txt", "r", stdin);
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &q[i]);
int ind = 0;
fill_prime(q[i], ind);
find_mult(ind);
for (int i = 0; i < 12; i++)
prime[i] = alfa[i] = 0;
}
ll ret = 0;
for (int i = 0; i < 2000001; ++i)
if(ans[q[i]]) ret += ans[q[i]] - 1;
printf("%lld\n", ret);
return 0;
}