-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGp_hash_table
123 lines (103 loc) · 2.99 KB
/
Gp_hash_table
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//https://codeforces.com/contest/1822/problem/G2
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define nn '\n'
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define UNIQUE(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end()))) ;
#define all(vec) vec.begin(),vec.end()
//#define int long long
#define pii pair<int,int>
#define pdd pair<double,double>
#define ff first
#define ss second
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
using namespace std ;
typedef long long LL ;
const int MOD=1e9+7,Base=998244353 ;
const int N=2e6+7 ;
const int oo=1LL*1000*1000*1000*1000*1000*1000+7LL ;
const double pie=acos(-1.0) ;
const double EPS=1e-9 ;
int test, n, a, t, tot ;
struct custom_hash
{
static uint64_t splitmix64(uint64_t x)
{
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
{
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash
{
int operator()(int x) const
{
return x ^ RANDOM;
}
};
int32_t main()
{
IOS
cin>>test ;
while(test--)
{
cin>>n ;
gp_hash_table<int,int,custom_hash>oc ;
vector<int>v ;
for(int i=1; i<=n; i++)
{
cin>>a ;
oc[a]++ ;
v.pb(a) ;
}
sort(all(v)) ;
UNIQUE(v) ;
long long ans = 0 ;
for(auto x:v)
{
int y = oc[x] ;
//cout<<" x "<<x<<" y "<<y<<endl ;
ans+=((LL)y*(y-1)*(y-2)) ;
for(int i=2; (LL)i*i<=(LL)x; i++)
{
if((LL)x*i>MOD)break ;
if(x%i==0)
{
//cout<<" s1 "<<x/i<<" x "<<x<<" x*d "<<x*i<<endl ;
ans+=(LL)oc[x]*oc[x*i]*oc[x/i] ;
y = x/i ;
if(y!=i)
{
if((LL)y*x<MOD)
ans+=(LL)oc[x]*oc[x*y]*oc[x/y] ;
}
}
}
//cout<<" x "<<x<<" x*x "<<x*x<<" 1 "<<1<<endl ;
if(x>1 and (LL)x*x<(LL)MOD)
ans+=(LL)oc[x]*oc[(LL)x*x]*oc[1] ;
//cout<<x
}
cout<<ans<<endl ;
}
/**/
return 0 ;
}