-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYetAnotherArrayProblem.cpp
More file actions
67 lines (53 loc) · 1.16 KB
/
YetAnotherArrayProblem.cpp
File metadata and controls
67 lines (53 loc) · 1.16 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
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;
using i128 = __int128;
std::vector<int> minp, primes;
void sieve(int n) {
minp.assign(n + 1, 0);
primes.clear();
for (int i = 2; i <= n; i++) {
if (minp[i] == 0) {
minp[i] = i;
primes.push_back(i);
}
for (auto p : primes) {
if (i * p > n) {
break;
}
minp[i * p] = p;
if (p == minp[i]) {
break;
}
}
}
}
void solve() {
int n;
std::cin >> n;
int ans = 1E9;
std::vector<i64> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
for (auto p : primes) {
if (a[i] % p) {
ans = std::min<int>(ans, p);
break;
}
}
}
std::cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
sieve(1000);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}