-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1968A.cpp
More file actions
48 lines (39 loc) · 930 Bytes
/
Copy path1968A.cpp
File metadata and controls
48 lines (39 loc) · 930 Bytes
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
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define umap unordered_map
#define f(i, x, n) for(ll i = x; i < n; i++)
#define endl '\n'
#define optimize() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
bool isPrime(ll x) {
if (x == 2) return true;
for (ll i = 2; i*i <= x; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
int main() {
optimize();
ll t;
cin >> t;
while (t--) {
ll x;
cin >> x;
if (isPrime(x)) {
cout << x-1 << endl;
} else {
ll mxsum = LLONG_MIN;
ll mx = LLONG_MIN;
for (ll i = 2; i < x; i++) {
if ((__gcd(x, i) + i) > mxsum) {
mxsum = __gcd(x, i) + i;
mx = i;
}
}
cout << mx << endl;
}
}
}