-
Notifications
You must be signed in to change notification settings - Fork 0
/
kth_divisor.cpp
48 lines (44 loc) · 1.19 KB
/
kth_divisor.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
//Problem: https://codeforces.com/contest/762/problem/A
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
#define s(v) sort(v.begin(), v.end())
#define rev(v) sort(v.rbegin(), v.rend())
#define bs(v, s) binary_search(v.begin(), v.end(), s)
#define minvec(v) *min_element(v.begin(), v.end())
#define maxvec(v) *max_element(v.begin(), v.end())
#define mp make_pair
#define pb(x) push_back(x)
#define fst first
#define sec second
#define foru(i, n, ty, x) for (int i = n; i < ty; i += x)
#define ford(i, n, ty, x) for (int i = n; i >= ty; i -= x)
#define forn(i, ty) foru(i, 0, ty, 1)
void setIO(string name) {
cin.tie(0)->sync_with_stdio(0);
if (name != "") {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
void solve() {
int n,k; cin >> n >> k;
vi a;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
a.pb(i);
if (i * i != n) a.pb(n/i);
}
}
s(a);
cout << (k > a.size() ? -1 : a[--k]);
}
int32_t main() {
setIO("");
// int t; cin >> t; while(t--)
solve();
}