-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprmdiv.cpp
More file actions
59 lines (59 loc) · 1.05 KB
/
prmdiv.cpp
File metadata and controls
59 lines (59 loc) · 1.05 KB
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
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pr pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MAX 1000001
typedef long long ll;
vector<int> primes;
void sieve() {
vector<bool> b(MAX,true);
b[0]=false;
b[1]=false;
for(long i=2;i*i<MAX;i++) {
if(b[i]==true) {
for(int j=i;j*i<MAX;j++) {
b[j*i]=false;
}
}
}
primes.pb(2);
for(long i=3;i<MAX;i+=2) {
if(b[i])
primes.pb(i);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
sieve();
int t;
cin>>t;
while(t--) {
int n;
cin>>n;
vector<int> A(n),S(n,0);
for(int i=0;i<n;i++) {
cin>>A[i];
for(int j=0;primes[j]<=A[i];j++) {
if(A[i]%primes[j]==0) {
S[i]+=primes[j];
}
}
}
long ans=0;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
if(i==j)
continue;
if(A[j]%A[i]==0&&S[j]%S[i]==0)
ans++;
}
}
cout<<ans<<"\n";
}
return 0;
}