-
Notifications
You must be signed in to change notification settings - Fork 0
/
D.cpp
130 lines (116 loc) · 2.39 KB
/
D.cpp
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
124
125
126
127
128
129
130
// optimizing yovanel's code
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vstr;
typedef vector<vstr> vvstr;
typedef pair<ll, ll> pll;
typedef pair<bool, bool> pb;
typedef pair<ld, ld> pld;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<pb> vpb;
typedef vector<vpb> vvpb;
typedef vector<pld> vpld;
typedef vector<vpld> vvpld;
#define F first
#define S second
#define FAST ios_base::sync_with_stdio(0)
#define FASTIN cin.tie(0)
#define FASTOUT cout.tie(0)
#define upmin(a, b) a = min(a, b)
#define upmax(a, b) a = max(a, b)
#define TER_CHAR '‰'
const ll mod = 1e9 + 7;
const ll big = 1e15;
const int maxn = 1000010;
vll m[maxn];
bitset<maxn> done = 0;
ll arr[maxn];
void sieve() {
for(int i = 0; i < maxn; ++i) {
m[i].clear();
}
done = 0;
for (ll i = 2; i < maxn; i++)
{
if (done[i]) continue;
m[i].push_back(i);
for (ll j = 2*i; j < maxn; j += i)
{
done[j] = true;
ll curdiv = 0;
ll jt = j;
while (jt % i == 0)
{
curdiv++;
jt /= i;
}
if (curdiv & 0x1) m[j].push_back(i);
}
}
}
void solve()
{
ll n;
cin >> n;
for (ll i = 0; i < n; i++) {
cin >> arr[i];
}
map<vll, ll> s;
for (ll i = 0; i < n; i++) {
ll cur = arr[i];
auto it = s.find(m[cur]);
if (it == s.end())
{
s.insert({ m[cur], 1 });
}
else (it->second)++;
}
ll ans0 = 0;
ll joiningsum = 0;
for (const auto& it : s)
{
ans0 = max(ans0, it.second);
if (it.first.size() == 0 || it.second % 2 == 0)
{
joiningsum += it.second;
}
}
ll ans1 = joiningsum;
ans1 = max(ans1, ans0);
ll q;
cin >> q;
while (q--)
{
ll pow; cin >> pow;
if (pow == 0) cout << ans0 << endl;
else cout << ans1 << endl;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
sieve();
int test;
cin >> test;
while (test--)
{
solve();
}
}