-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path111.cpp
More file actions
36 lines (32 loc) · 823 Bytes
/
Copy path111.cpp
File metadata and controls
36 lines (32 loc) · 823 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
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long k;
if (cin >> k) {
if (k <= 2) {
cout << 0 << "\n";
} else if (k % 3 == 0) {
cout << 2 << "\n";
} else if (k % 4 == 0) {
cout << 3 << "\n";
} else {
long long ans = -1;
for (long long i = 5; i * i <= k; i += 2) {
if (k % i == 0) {
ans = i - 1;
break;
}
}
if (ans != -1) {
cout << ans << "\n";
} else if (k % 2 == 0) {
cout << (k / 2) - 1 << "\n";
} else {
cout << k - 1 << "\n";
}
}
}
return 0;
}