10997 | 2024-06-01 16:46:25 | szil | Geometric Mean | cpp17 | Accepted 100/100 | 527ms | 30352 KiB |
#include <bits/stdc++.h>
#include <iterator>
using ll = long long;
using namespace std;
const int MAXN = 1'000'001;
const ll INF = 1e12 + 1;
int szita[MAXN];
void solve() {
int n;
cin >> n;
vector<ll> v(n + 1);
vector<vector<int> > p(n + 1);
unordered_map<ll, int> m;
for(int i = 1; i <= n; i++)
{
cin >> v[i];
int x = v[i];
while(x != 1)
{
p[i].push_back(szita[x]);
x /= szita[x];
}
}
ll ans = 0;
vector<vector<ll> > ins(n + 2);
for(int i = 1; i <= n; i++)
{
for(auto x : ins[i]) m[x]++;
for(int j = i + 1; j <= n; j++) {
vector<int> pt;
merge(p[i].begin(), p[i].end(), p[j].begin(), p[j].end(), back_inserter(pt));
pt.push_back(1);
ll w = 1;
ll la = 1, db = 0;
ll mul = v[i] * v[j];
for(auto x : pt)
{
if(x == la)
{
db++;
}
if(x != la)
{
ll m = 1;
while(db >= 4)
{
for(int i = 0; i < 4; i++) mul /= la;
db -= 4;
}
int z = (4 - db) % 4;
for(int i = 0; i < z; i++)
{
if(w == -1) continue;
w *= la;
if(w > INF) w = -1;
}
db = 1;
}
la = x;
}
ans += m[w];
ins[j + 1].push_back(mul);
}
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
for (int i = 2; i < MAXN; i++) {
if (!szita[i]) {
szita[i] = i;
for (int j = 2*i; j < MAXN; j += i) {
if (!szita[j]) szita[j] = i;
}
}
}
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 17ms | 4324 KiB | ||||
2 | Accepted | 14ms | 4324 KiB | ||||
3 | Accepted | 17ms | 4324 KiB | ||||
subtask2 | 10/10 | ||||||
4 | Accepted | 17ms | 4240 KiB | ||||
5 | Accepted | 17ms | 4324 KiB | ||||
6 | Accepted | 16ms | 4328 KiB | ||||
7 | Accepted | 17ms | 4452 KiB | ||||
8 | Accepted | 17ms | 4324 KiB | ||||
9 | Accepted | 17ms | 4324 KiB | ||||
10 | Accepted | 17ms | 4196 KiB | ||||
11 | Accepted | 17ms | 4452 KiB | ||||
12 | Accepted | 16ms | 4196 KiB | ||||
13 | Accepted | 16ms | 4256 KiB | ||||
14 | Accepted | 14ms | 4488 KiB | ||||
15 | Accepted | 16ms | 4456 KiB | ||||
16 | Accepted | 16ms | 4480 KiB | ||||
17 | Accepted | 16ms | 4452 KiB | ||||
18 | Accepted | 16ms | 4584 KiB | ||||
subtask3 | 10/10 | ||||||
19 | Accepted | 17ms | 4240 KiB | ||||
20 | Accepted | 17ms | 4324 KiB | ||||
21 | Accepted | 16ms | 4328 KiB | ||||
22 | Accepted | 17ms | 4452 KiB | ||||
23 | Accepted | 17ms | 4324 KiB | ||||
24 | Accepted | 17ms | 4324 KiB | ||||
25 | Accepted | 17ms | 4196 KiB | ||||
26 | Accepted | 17ms | 4452 KiB | ||||
27 | Accepted | 16ms | 4196 KiB | ||||
28 | Accepted | 16ms | 4256 KiB | ||||
29 | Accepted | 14ms | 4488 KiB | ||||
30 | Accepted | 16ms | 4456 KiB | ||||
31 | Accepted | 16ms | 4480 KiB | ||||
32 | Accepted | 16ms | 4452 KiB | ||||
33 | Accepted | 16ms | 4584 KiB | ||||
34 | Accepted | 16ms | 4388 KiB | ||||
35 | Accepted | 16ms | 4228 KiB | ||||
36 | Accepted | 17ms | 4472 KiB | ||||
37 | Accepted | 17ms | 4324 KiB | ||||
38 | Accepted | 14ms | 4252 KiB | ||||
39 | Accepted | 17ms | 4252 KiB | ||||
40 | Accepted | 17ms | 4452 KiB | ||||
41 | Accepted | 16ms | 4344 KiB | ||||
42 | Accepted | 17ms | 4252 KiB | ||||
43 | Accepted | 16ms | 4344 KiB | ||||
44 | Accepted | 16ms | 4324 KiB | ||||
45 | Accepted | 17ms | 4472 KiB | ||||
subtask4 | 10/10 | ||||||
46 | Accepted | 18ms | 4284 KiB | ||||
47 | Accepted | 98ms | 5580 KiB | ||||
48 | Accepted | 208ms | 7680 KiB | ||||
49 | Accepted | 337ms | 9764 KiB | ||||
50 | Accepted | 342ms | 9828 KiB | ||||
51 | Accepted | 347ms | 9700 KiB | ||||
52 | Accepted | 351ms | 9828 KiB | ||||
53 | Accepted | 361ms | 9828 KiB | ||||
54 | Accepted | 342ms | 9700 KiB | ||||
subtask5 | 25/25 | ||||||
55 | Accepted | 17ms | 4240 KiB | ||||
56 | Accepted | 17ms | 4324 KiB | ||||
57 | Accepted | 16ms | 4328 KiB | ||||
58 | Accepted | 17ms | 4452 KiB | ||||
59 | Accepted | 17ms | 4324 KiB | ||||
60 | Accepted | 17ms | 4324 KiB | ||||
61 | Accepted | 17ms | 4196 KiB | ||||
62 | Accepted | 17ms | 4452 KiB | ||||
63 | Accepted | 16ms | 4196 KiB | ||||
64 | Accepted | 16ms | 4256 KiB | ||||
65 | Accepted | 14ms | 4488 KiB | ||||
66 | Accepted | 16ms | 4456 KiB | ||||
67 | Accepted | 16ms | 4480 KiB | ||||
68 | Accepted | 16ms | 4452 KiB | ||||
69 | Accepted | 16ms | 4584 KiB | ||||
70 | Accepted | 16ms | 4388 KiB | ||||
71 | Accepted | 16ms | 4228 KiB | ||||
72 | Accepted | 17ms | 4472 KiB | ||||
73 | Accepted | 17ms | 4324 KiB | ||||
74 | Accepted | 14ms | 4252 KiB | ||||
75 | Accepted | 17ms | 4252 KiB | ||||
76 | Accepted | 17ms | 4452 KiB | ||||
77 | Accepted | 16ms | 4344 KiB | ||||
78 | Accepted | 17ms | 4252 KiB | ||||
79 | Accepted | 16ms | 4344 KiB | ||||
80 | Accepted | 16ms | 4324 KiB | ||||
81 | Accepted | 17ms | 4472 KiB | ||||
82 | Accepted | 25ms | 5220 KiB | ||||
83 | Accepted | 23ms | 4744 KiB | ||||
84 | Accepted | 30ms | 4624 KiB | ||||
85 | Accepted | 35ms | 4660 KiB | ||||
86 | Accepted | 23ms | 4580 KiB | ||||
87 | Accepted | 28ms | 4532 KiB | ||||
88 | Accepted | 28ms | 4580 KiB | ||||
89 | Accepted | 18ms | 4580 KiB | ||||
90 | Accepted | 32ms | 4560 KiB | ||||
91 | Accepted | 32ms | 5268 KiB | ||||
92 | Accepted | 27ms | 5224 KiB | ||||
93 | Accepted | 27ms | 5260 KiB | ||||
94 | Accepted | 27ms | 5420 KiB | ||||
95 | Accepted | 27ms | 5216 KiB | ||||
96 | Accepted | 26ms | 5220 KiB | ||||
subtask6 | 45/45 | ||||||
97 | Accepted | 17ms | 4240 KiB | ||||
98 | Accepted | 17ms | 4324 KiB | ||||
99 | Accepted | 16ms | 4328 KiB | ||||
100 | Accepted | 17ms | 4452 KiB | ||||
101 | Accepted | 17ms | 4324 KiB | ||||
102 | Accepted | 17ms | 4324 KiB | ||||
103 | Accepted | 17ms | 4196 KiB | ||||
104 | Accepted | 17ms | 4452 KiB | ||||
105 | Accepted | 16ms | 4196 KiB | ||||
106 | Accepted | 16ms | 4256 KiB | ||||
107 | Accepted | 14ms | 4488 KiB | ||||
108 | Accepted | 16ms | 4456 KiB | ||||
109 | Accepted | 16ms | 4480 KiB | ||||
110 | Accepted | 16ms | 4452 KiB | ||||
111 | Accepted | 16ms | 4584 KiB | ||||
112 | Accepted | 16ms | 4388 KiB | ||||
113 | Accepted | 16ms | 4228 KiB | ||||
114 | Accepted | 17ms | 4472 KiB | ||||
115 | Accepted | 17ms | 4324 KiB | ||||
116 | Accepted | 14ms | 4252 KiB | ||||
117 | Accepted | 17ms | 4252 KiB | ||||
118 | Accepted | 17ms | 4452 KiB | ||||
119 | Accepted | 16ms | 4344 KiB | ||||
120 | Accepted | 17ms | 4252 KiB | ||||
121 | Accepted | 16ms | 4344 KiB | ||||
122 | Accepted | 16ms | 4324 KiB | ||||
123 | Accepted | 17ms | 4472 KiB | ||||
124 | Accepted | 18ms | 4284 KiB | ||||
125 | Accepted | 98ms | 5580 KiB | ||||
126 | Accepted | 208ms | 7680 KiB | ||||
127 | Accepted | 337ms | 9764 KiB | ||||
128 | Accepted | 342ms | 9828 KiB | ||||
129 | Accepted | 347ms | 9700 KiB | ||||
130 | Accepted | 351ms | 9828 KiB | ||||
131 | Accepted | 361ms | 9828 KiB | ||||
132 | Accepted | 342ms | 9700 KiB | ||||
133 | Accepted | 25ms | 5220 KiB | ||||
134 | Accepted | 23ms | 4744 KiB | ||||
135 | Accepted | 30ms | 4624 KiB | ||||
136 | Accepted | 35ms | 4660 KiB | ||||
137 | Accepted | 23ms | 4580 KiB | ||||
138 | Accepted | 28ms | 4532 KiB | ||||
139 | Accepted | 28ms | 4580 KiB | ||||
140 | Accepted | 18ms | 4580 KiB | ||||
141 | Accepted | 32ms | 4560 KiB | ||||
142 | Accepted | 32ms | 5268 KiB | ||||
143 | Accepted | 27ms | 5224 KiB | ||||
144 | Accepted | 27ms | 5260 KiB | ||||
145 | Accepted | 27ms | 5420 KiB | ||||
146 | Accepted | 27ms | 5216 KiB | ||||
147 | Accepted | 26ms | 5220 KiB | ||||
148 | Accepted | 389ms | 30352 KiB | ||||
149 | Accepted | 172ms | 10128 KiB | ||||
150 | Accepted | 412ms | 9820 KiB | ||||
151 | Accepted | 527ms | 9828 KiB | ||||
152 | Accepted | 137ms | 9700 KiB | ||||
153 | Accepted | 347ms | 9744 KiB | ||||
154 | Accepted | 342ms | 9796 KiB | ||||
155 | Accepted | 104ms | 9672 KiB | ||||
156 | Accepted | 368ms | 9828 KiB | ||||
157 | Accepted | 361ms | 11328 KiB | ||||
158 | Accepted | 328ms | 22536 KiB | ||||
159 | Accepted | 386ms | 28984 KiB | ||||
160 | Accepted | 442ms | 30160 KiB | ||||
161 | Accepted | 393ms | 29104 KiB | ||||
162 | Accepted | 453ms | 29260 KiB | ||||
163 | Accepted | 305ms | 9828 KiB | ||||
164 | Accepted | 273ms | 21432 KiB |