-
Notifications
You must be signed in to change notification settings - Fork 1
/
BOJ_19577.cpp
58 lines (53 loc) · 1.11 KB
/
BOJ_19577.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
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 1000000000
const ll INF = 10e12 + 10;
using namespace std;
vector<int> v;
void measure(int n) {
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
v.push_back(i);
if (n / i != i)v.push_back(n / i);
}
}
}
int phi(int n) {
int ans = n;
for (int k = 2; k <= sqrt(n); k++) {
if (n % k == 0) {
ans -= ans / k;
while (n % k == 0) n /= k;
}
}
if (n > 1)ans -= ans / n;
return ans;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
if (n == 1) {
cout << 1;
return 0;
}
if (n % 2) {
cout << -1;
} else {
measure(n);
sort(v.begin(), v.end());
// for (auto iter: v) {
// cout << iter << " ";
// }
for (auto x: v) {
if (x * phi(x) == n) {
cout << x;
return 0;
}
}
cout << -1;
}
}