-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathKanishk.cpp
More file actions
42 lines (41 loc) · 1.07 KB
/
Kanishk.cpp
File metadata and controls
42 lines (41 loc) · 1.07 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
#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int k;
cin >> k;
vector<int> v(k);
unordered_map<int, int> d;
for (int i = 0; i < k; ++i) {
cin >> v[i];
d[v[i]]++;
}
if (d[1] > 0 && d[k - 2] > 0) {
cout << 1 << " " << k - 2 << endl;
continue;
}
bool f = false;
for (int i = 2; i * i <= k - 2; ++i) {
if ((k - 2) % i == 0) {
int a = i, b = (k - 2) / i;
if (a == b) {
if (d[a] > 1) {
cout << a << " " << a << endl;
f = true;
break;
}
} else if (d[a] > 0 && d[b] > 0) {
cout << a << " " << b << endl;
f = true;
break;
}
}
if (!f) cout << "No valid factors" << endl;
}
return 0;
}